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/24/2019 at 15:410 Comments

Printnum is the routine that converts a 16-bit binary number to a 5-digit ascii string.

I covered it a few days ago - but was not happy with the large blocks of code that were repeated 4 times over.

Now that I have the CALL and RET subroutine mechanism working, I decided to rewrite the routine using one subroutine labelled "Decimate" that is called 4 times, each time with a different decimation factor (10,000, 1000, 100 and 10) stored in R1.  

The result is much simpler and shorter code - and easier to understand. It is 39 words long, whereas its predecessor was 84 words.

Here is the new version printnum_2

         // 0x0010 ---------------------------PRINTNUM_2----------------------------------------- 

    //  R1 = Decimation Value
    //  R2 = digit 
    //  R3 = 0x30
    //  R4 = temporary storage for accumulator (decimated value)
        0x1200,     // SET R2, 0x0000
        0x1300,     // SET R3, 0x0030
        0x1100,     // R1 =  10,000
        0x082C,     // CALL decimate
        0x1100,     // R1 = 1000
        0x082C,     // CALL decimate
        0x1100,     // R1 = 100
        0x082C,     // CALL decimate
        0x1100,     // R1 = 10
        0x082C,     // CALL decimate
     // 0x0020 ---------------------------------------------------------
        0xA300,     // ADD R0, R3 to make a number
        0x0C00,     // putchar R0
        0xB300,     // SUB R3 to restore accumulator
        0x1000,     // SET R0, CR
        0x0C00,     // putchar R0 CR
        0x1000,     // Set R0, LF
        0x0C00,     // putchar R0 LF
        0x0000,     // BRA START     
        0x0F00,     // NOP
        0x0F00,     // NOP
     // 0x002C ------------------------Decimate--------------------------------
        0xB100,     // SUB R1,     :Decimate 
        0x0230,     // BLT 0x30    
        0xE200,     // INC R2
        0x002C,     // BRA 0x02C

     // 0x0030 ---------------------------------------------------------    

        0x3400,     // Store R0 in R4   
        0x2200,     // MOV R2, R0,  
        0xA300,     // ADD R0, R3 to make a number
        0x0C00,     // putchar R0
        0x2400,     // Get R0 back from R4                 
        0xA100,     // ADD R1 adds DEC value to restore R0       
        0x1200,     // SET R2,0    Reset R2

        0x0900,     // RET