Close

Added JSR/RTS to IOP16

A project log for 8 Bit Computer Front Panel

VHDL code for I2C Control of Front Panel with 32 pushbuttons and 32 LEDs

land-boardscomland-boards.com 06/19/2021 at 13:410 Comments

Created a new IOP16 which adds Jump to Subroutine (JSR) and Return from Subroutine (RTS) opcodes to the IOP16 (in new IOP16B VHDL code). This is a single level only. Implementing nested subroutines would require stack memory and additional resources (another 2 memory blocks). A short LIFO could probably be implemented in logic/registers but isn't worthwhile in this application since a single level is enough.

This allows the in-line I2C functions to be replaced with subroutines and greatly shortens the code length. The code runs slower due to the added burden of the two instructions, but this is not a significant issue since speed it not a particular concern. because the I2C interface runs much slower than the CPU.

This implies the passed parameters need to be placed in specific registers which requires careful control.

Example of writing a value to an I2C register - before the change.

After the change - the calling code is:

The I2C subroutine code is:

Register Allocations

Code Size Reduction

The code size before the change was 975 lines and 243 lines after creating I2C read/I2C write subroutines (JSR and RTS). That's a 75% reduction in code size. 

The GitHub branch is here. The code that is run is FP01_LOOP3.

It works!

Discussions