Close

Immediate Instructions

A project log for Suite-16

Suite-16 is a 16-bit cpu built entirely from TTL. It is a personal exploration of how hardware and software interact.

monsonitemonsonite 10/29/2019 at 13:140 Comments

One of the deficiencies with the Suit-16 instruction set was a lack of an immediate addressing mode, where one of the operands is contained in the next word in memory.

This specifically was becoming a problem when you wanted to check if the contents of the accumulator lay between two bounds - and branch accordingly.  This type of test is frequently found in ascii to hex or decimal conversion routines and string handling, and after coding a few routines it became obvious that the current situation involving other registers was clumsy and inadequate.

As a compromise I have added two instructions ADI and SBI which allow an 8-bit value to be coded into the payload area and have it added to or subtracted from the accumulator.

I have coded these two instructions in the spare 0x0Axx  and 0x0Bxx instruction slots to try them out  and see if they make coding easier and less convoluted. If they are useful they will get added to the final instruction set that will be implemented in hardware.

Here's an example from the Number entry routine where the input character needs to be tested to find out if it falls between ASCII 0x30 and 0x39 and is therefore a decimal digit.  Registers  R2 and R3 are first preloaded with the constants 0x0A and 0x30 so that they are available for the tests.  These preload instructions will not be needed, saving 4 words of memory,  and the SUB R3 and SUB R2 instructions become  SBI 0x30 and SBI 0x0A respectively.

Whilst this might seem a trivial change in this example, it will be very useful when testing the input buffer for certain known strings - essential for dealing with high-level languages with keywords.

        0x1300,     // SET R3 0x30   Preload R3 with decimal 48
        0x0030,
        0x1200,     // SET R2, 0x0A  Preload R2 with decimal 10
        0x000A,
        
        0x1100,     // SET R1, 0x0200    text buffer start
        0x0200,
        0x4100,     // LD AC, @R1  get first character from buffer
        0x3400,     // Store R0 in R4
        
        0xE100,     // INC R1
        0x4100,     // LD AC, @R1  get next character - and test to see if it is a number
        0xB300,     // Subtract R3 Is it bigger than 0x30?
        0x025A,     // BLT Not a Number
        
        0xB200,     // Subtract R2  0x0A
        0x035A,     // BGE Not a Number
        0x2400,     // Get original character  R0 back from R4
        0xB300,     // Subtract R3 to form a digit

Discussions