Simple CPU v1d2: Reference Guide

Home

A summary of documents taken from SimpleCPU lectures, practicals and web pages, please refer back to these for more detailed information / explanation: (Link).

Figure 1 : SimpleCPU_v1d block diagram

This processor uses a fixed length 16bit instruction format. Memory is 4096 x 16bit, allowing an instruction to be stored in a single memory location. On reset the first instruction is fetched from address 0. The data processing unit i.e. ALU, is 16bit wide. The register file contains 4 x 16bit general purpose registers : RA – RD. The CALL-RET stack is implemented using internal memory within the PC component and is limited to a depth of 8 i.e. max of eight nested subroutine calls. This stack is not accessible using software. Parameters must be passed between the main program and subroutines using external memory or registers. To simplify the hardware implementation this CPU has separate 16bit data-in and data-out buses. This processor does not support byte addressable memory. Supports 53 instructions.

Instruction formats

Figure 2 : SimpleCPU_v1d2 instruction formats

Figure 3 : status register, flags.

Instruction set summary table

##################################
# SIMPLECPU V1D2 INSTRUCTION-SET #
##################################

INSTR   IR15 IR14 IR13 IR12 IR11 IR10 IR09 IR08 IR07 IR06 IR05 IR04 IR03 IR02 IR01 IR00  
MOVE    0    0    0    0    RD   RD   0    0    K    K    K    K    K    K    K    K
MOVEH   0    0    0    0    RD   RD   0    1    K    K    K    K    K    K    K    K
MOVEU   0    0    0    0    RD   RD   1    0    K    K    K    K    K    K    K    K

ADD     0    0    0    1    RD   RD   0    0    K    K    K    K    K    K    K    K
ADDU    0    0    0    1    RD   RD   0    1    K    K    K    K    K    K    K    K
ADDC    0    0    0    1    RD   RD   1    0    K    K    K    K    K    K    K    K
SUB     0    0    1    0    RD   RD   0    0    K    K    K    K    K    K    K    K
SUBU    0    0    1    0    RD   RD   0    1    K    K    K    K    K    K    K    K
SUBC    0    0    1    0    RD   RD   0    1    K    K    K    K    K    K    K    K

AND     0    0    1    1    RD   RD   0    0    K    K    K    K    K    K    K    K
OR      0    0    1    1    RD   RD   0    1    K    K    K    K    K    K    K    K
XOR     0    0    1    1    RD   RD   1    0    K    K    K    K    K    K    K    K

LOAD    0    1    0    0    A    A    A    A    A    A    A    A    A    A    A    A
STORE   0    1    0    1    A    A    A    A    A    A    A    A    A    A    A    A
ADDM    0    1    1    0    A    A    A    A    A    A    A    A    A    A    A    A
SUBM    0    1    1    1    A    A    A    A    A    A    A    A    A    A    A    A

JUMPU   1    0    0    0    A    A    A    A    A    A    A    A    A    A    A    A
JUMPZ   1    0    0    1    0    0    0    R    R    R    R    R    R    R    R    R  -- RELATIVE -256 to +255
JUMPNZ  1    0    0    1    0    0    1    R    R    R    R    R    R    R    R    R
JUMPC   1    0    0    1    0    1    0    R    R    R    R    R    R    R    R    R 
JUMPNC  1    0    0    1    0    1    1    R    R    R    R    R    R    R    R    R
JUMPO   1    0    0    1    1    0    0    R    R    R    R    R    R    R    R    R 
JUMPNO  1    0    0    1    1    0    1    R    R    R    R    R    R    R    R    R 
JUMPN   1    0    0    1    1    1    0    R    R    R    R    R    R    R    R    R
JUMPP   1    0    0    1    1    1    1    R    R    R    R    R    R    R    R    R 

CMP     1    0    1    0    RD   RD   0    0    K    K    K    K    K    K    K    K  
TEST    1    0    1    0    RD   RD   0    1    K    K    K    K    K    K    K    K  
MULU    1    0    1    1    RD   RD   X    X    K    K    K    K    K    K    K    K 
 
ADDMC   1    1    0    0    A    A    A    A    A    A    A    A    A    A    A    A  
SUBMC   1    1    0    1    A    A    A    A    A    A    A    A    A    A    A    A 
 
CALL    1    1    1    0    A    A    A    A    A    A    A    A    A    A    A    A
RET     1    1    1    1    X    X    X    X    X    X    X    0    0    0    0    0

MOVE    1    1    1    1    RD   RD   RS   RS   X    X    X    0    0    0    0    1
LOAD    1    1    1    1    RD   RD   RS   RS   X    X    X    0    0    0    1    0  -- REG INDIRECT
STORE   1    1    1    1    RD   RD   RS   RS   X    X    X    0    0    0    1    1  -- REG INDIRECT   
ROL     1    1    1    1    RSD  RSD  X    X    X    X    X    0    0    1    0    0  
ROR     1    1    1    1    RSD  RSD  X    X    X    X    X    0    0    1    0    1

ADD     1    1    1    1    RD   RD   RS   RS   X    X    X    0    0    1    1    0  
SUB     1    1    1    1    RD   RD   RS   RS   X    X    X    0    0    1    1    1  
AND     1    1    1    1    RD   RD   RS   RS   X    X    X    0    1    0    0    0  
OR      1    1    1    1    RD   RD   RS   RS   X    X    X    0    1    0    0    1 
XOR     1    1    1    1    RD   RD   RS   RS   X    X    X    0    1    0    1    0
ASL     1    1    1    1    RSD  RSD  X    X    X    X    X    0    1    0    1    1  
ASR     1    1    1    1    RSD  RSD  X    X    X    X    X    0    1    1    0    0  
SHL     1    1    1    1    RD   RD   X    X    X    X    X    0    1    1    0    1  
SHR     1    1    1    1    RD   RD   X    X    X    X    X    0    1    1    1    0 
 
ADDC    1    1    1    1    RD   RD   RS   RS   X    X    X    0    1    1    1    1
SUBC    1    1    1    1    RD   RD   RS   RS   X    X    X    1    0    0    0    0 
CMP     1    1    1    1    RD   RD   RS   RS   X    X    X    1    0    0    0    1 
TEST    1    1    1    1    RD   RD   RS   RS   X    X    X    1    0    0    1    0 
MULU    1    1    1    1    RD   RD   RS   RS   X    X    X    1    0    0    1    1 

Figure 4 : instruction formats

Instruction set

Move

Example            :    move RA 0x80
Addressing mode    :    immediate
Opcode             :    0000 00
RTL                :    RX <- ( (K7)8 || KK )
Flags set          :    None

Move signed 8bit value into general purpose register. The bit field KK is as defined in figure 2. In this example RX is register RA and KK is the value 0x80, signed extended to 16bits. Therefore, at the end of the execution phase the register RA=0xFF80.

Moveh

Example            :    moveh RA 0x80
Addressing mode    :    immediate
Opcode             :    0000 + 01
RTL                :    RX <- ( KK || (0)8 )
Flags set          :    None

Move an 8bit value into the high byte of a general purpose register. Low byte set to 0x00. The bit field KK is as defined in figure 2. In this example RX is register RA and KK is the value 0x80. Therefore, at the end of the execution phase the register RA=0x8000.

Moveu

Example            :    moveu RA 0x80
Addressing mode    :    immediate
Opcode             :    0000 + 10
RTL                :    RX <- ( (0)8 || KK )
Flags set          :    None

Move an 8bit value into the low byte of a general purpose register. High byte set to 0x00. The bit field KK is as defined in figure 2. In this example RX is register RA and KK is the value 0x80. Therefore, at the end of the execution phase the register RA=0x0080.

Add

Example            :    add RB 2
Addressing mode    :    immediate
Opcode             :    0001 + 00
RTL                :    RX <- RX + ( (K7)8 || KK )
Flags set          :    Z,C,O,P,N

Add signed 8bit value to general purpose register. The bit field KK is as defined in figure 2. In this example RX is register RB and KK is the value 2, signed extended to 16bits. Therefore, if RB=1 at the end of the execution phase register RB=3.

Addu

Example            :    add RB 0x80
Addressing mode    :    immediate
Opcode             :    0001 + 01
RTL                :    RX <- RX + ( (0)8 || KK )
Flags set          :    Z,C,O,P,N

Add unsigned 8bit value to general purpose register. The bit field KK is as defined in figure 2. In this example RX is register RB and KK is the value 2, high byte set to 0 to produce 16bit operand. Therefore, if RB=1 at the end of the execution phase register RB=0x81.

Addc

Example            :    addc RB 2
Addressing mode    :    immediate
Opcode             :    0001 + 10
RTL                :    RX <- RX + ( (K7)8 || KK ) + carry_flag
Flags set          :    Z,C,O,P,N

Add signed 8bit value + carry_flag (0/1) to general purpose register. The bit field KK is as defined in figure 2. In this example RX is register RB and KK is the value 2, signed extended to 16bits. Therefore, if RB=1 and C=1, at the end of the execution phase register RB=4.

Sub

Example            :    sub RC 3
Addressing mode    :    immediate
Opcode             :    0010 + 00
RTL                :    RX <- RX - ( (K7)8 || KK )
Flags set          :    Z,C,O,P,N

Subtract signed 8bit value from general purpose register. The bit field KK is as defined in figure 2. In this example RX is register RC and KK is the value 3, signed extended to 16bits. Therefore, if RC=5 at the end of the execution phase register RC=2.

Subu

Example            :    subu RC 0x80
Addressing mode    :    immediate
Opcode             :    0010 + 01
RTL                :    RX <- RX - ( (0)8 || KK )
Flags set          :    Z,C,O,P,N

Subtract unsigned 8bit value from general purpose register. The bit field KK is as defined in figure 2. In this example RX is register RC and KK is the value 3, high byte set to 0 to produce 16bit operand. Therefore, if RC=0x81 at the end of the execution phase register RC=1.

Subc

Example            :    subc RC 3
Addressing mode    :    immediate
Opcode             :    0010 + 10
RTL                :    RX <- RX - ( (K7)8 || KK ) - carry_flag
Flags set          :    Z,C,O,P,N

Subtract signed 8bit + carry_flag (0/1) value from general purpose register. The bit field KK is as defined in figure 2. In this example RX is register RC and KK is the value 3, signed extended to 16bits. Therefore, if RC=5 and C=1 at the end of the execution phase register RC=1.

And

Example            :    and RD 4
Addressing mode    :    immediate
Opcode             :    0011 + 00
RTL                :    RX <- RX & ( (0)8 || KK )
Flags set          :    Z,C,O,P,N

Perform 8bit bitwise AND on general purpose register. The bit field KK is as defined in figure 2. In this example RX is register RD and KK is the value 4, high byte set to 0 to produce 16bit operand. Therefore, if RD=7 at the end of the execution phase register RD=4. Note, as the value KK represents a binary pattern this data is not sign extended.

Or

Example            :    or RD 4
Addressing mode    :    immediate
Opcode             :    0011 + 01
RTL                :    RX <- RX & ( (0)8 || KK )
Flags set          :    Z,C,O,P,N

Perform 8bit bitwise OR on general purpose register. The bit field KK is as defined in figure 2. In this example RX is register RD and KK is the value 4, high byte set to 0 to produce 16bit operand. Therefore, if RD=3 at the end of the execution phase register RD=7. Note, as the value KK represents a binary pattern this data is not sign extended.

Xor

Example            :    xor RD 4
Addressing mode    :    immediate
Opcode             :    0011 + 10
RTL                :    RX <- RX & ( (0)8 || KK )
Flags set          :    Z,C,O,P,N

Perform 8bit bitwise AND on general purpose register. The bit field KK is as defined in figure 2. In this example RX is register RD and KK is the value 4, high byte set to 0 to produce 16bit operand. Therefore, if RD=7 at the end of the execution phase register RD=3. Note, as the value KK represents a binary pattern this data is not sign extended.

Load

Example            :    load RA 123
Addressing mode    :    absolute
Opcode             :    0100
RTL                :    RA <- M[AAA]
Flags set          :    None

Transfer a 16bit value from memory to general purpose register RA. The bit field AAA is as defined in figure 2. In this example AAA is the address 123, therefore, if M[123]=10 at the end of the execution phase register RA=10. Note, the destination register is hardwired to register RA, you can not use other registers.

Store

Example            :    store RA 234
Addressing mode    :    absolute
Opcode             :    0101
RTL                :    M[AAA] <- RA
Flags set          :    None

Store 16bit value in general purpose register RA to memory. The bit field AAA is as defined in figure 2. In this example AAA is the address 234, therefore, if RA=9 at the end of the execution phase memory location M[234]=9. Note, the source register is hardwired to register RA, you can not use other registers.

Addm

Example            :    addm RA 345
Addressing mode    :    absolute
Opcode             :    0110
RTL                :    RA <- RA + M[AAA]
Flags set          :    Z,C,O,P,N

Add 16bit value stored in memory to general purpose register RA. The bit field AAA is as defined in figure 2. In this example AAA is the address 345, therefore, if RA=20 and M[345]=10 at the end of the execution phase register RA=30. Note, the destination register is hardwired to register RA, you can not use other registers.

Subm

Example            :    subm RA 456
Addressing mode    :    absolute
Opcode             :    0111
RTL                :    RA <- RA - M[AAA]
Flags set          :    Z,C,O,P,N

Subtract 16bit value stored in memory from general purpose register RA. The bit field AAA is as defined in figure 2. In this example AAA is the address 456, therefore, if RA=20 and M[456]=10 at the end of the execution phase register RA=10. Note, the destination register is hardwired to register RA, you can not use other registers.

Jumpu or Jump

Example            :    jump 200
Addressing mode    :    direct
Opcode             :    1000
RTL                :    PC <- AAA
Flags set          :    None

Unconditional jump. The bit field AAA is as defined in figure 2. In this example AAA is the address 200, at the end of the execution phase the PC is updated to 200.

Jumpz

Example            :    jumpz 10
Addressing mode    :    relative
Opcode             :    1001 + 000
RTL                :    IF Z=1 THEN PC <- PC + RRR ELSE PC <- PC + 1
Flags set          :    None

Jump if last arithmetic or logical instruction produced a zero result i.e. jump is conditional on the status register’s Z flag. The bit field RRR is as defined in figure 2. In this example RRR is the relative offset 10, if Z=1 the PC is set to the value PC+10 at the end of the execution phase, else PC+1. Note, status register (Z flag) is only updated by arithmetic or logical functions.

Jumpnz

Example            :    jumpnz 511
Addressing mode    :    direct
Opcode             :    1001 + 001
RTL                :    IF Z=0 THEN PC <- PC + RRR ELSE PC <- PC + 1
Flags set          :    None

Jump if last arithmetic or logic instruction did not produce a zero result i.e. jump is conditional on the status register’s Z flag. The bit field RRR is as defined in figure 2. In this example RRR is the relative offset -1, if Z=0 the PC is set to the value PC-1 at the end of the execution phase, else PC+1. Note, status register (Z flag) is only updated by arithmetic or logical functions.

Jumpc

Example            :    jumpc 100
Addressing mode    :    direct
Opcode             :    1001 + 010
RTL                :    IF C=1 THEN PC <- PC + RRR ELSE PC <- PC + 1
Flags set          :    None

Jump if last arithmetic instruction generated a carry i.e. jump is conditional on the status register’s C flag. The bit field RRR is as defined in figure 2. In this example RRR the relative offset 100, if C=1 the PC is set to the value PC+100 at the end of the execution phase, else PC+1. Note, status register (C flag) is only updated by arithmetic functions.

Jumpnc

Example            :    jumpnc 508
Addressing mode    :    direct
Opcode             :    1001 + 011
RTL                :    IF C=0 THEN PC <- PC + RRR ELSE PC <- PC + 1
Flags set          :    None

Jump if last arithmetic instruction did not generated a carry i.e. jump is conditional on the status register’s C flag. The bit field RRR is as defined in figure 2. In this example RRR is the relative offset -4, if C=0 the PC is set to the value PC-4 at the end of the execution phase, else PC+1. Note, status register (C flag) is only updated by arithmetic functions.

Jumpo

Example            :    jumpo 104
Addressing mode    :    direct
Opcode             :    1001 + 100
RTL                :    IF O=1 THEN PC <- PC + RRR ELSE PC <- PC + 1
Flags set          :    None

Jump if last arithmetic instruction generated an overflow i.e. jump is conditional on the status register’s O flag. The bit field RRR is as defined in figure 2. In this example RRR the relative offset 104, if O=1 the PC is set to the value PC+104 at the end of the execution phase, else PC+1. Note, status register (O flag) is only updated by arithmetic functions.

Jumpno

Example            :    jumpno 504
Addressing mode    :    direct
Opcode             :    1001 + 101
RTL                :    IF O=0 THEN PC <- PC + RRR ELSE PC <- PC + 1
Flags set          :    None

Jump if last arithmetic instruction did not generated an overflow i.e. jump is conditional on the status register’s O flag. The bit field RRR is as defined in figure 2. In this example RRR is the relative offset -4, if O=0 the PC is set to the value PC-8 at the end of the execution phase, else PC+1. Note, status register (O flag) is only updated by arithmetic functions.

Jumpn

Example            :    jumpn 5
Addressing mode    :    direct
Opcode             :    1001 + 110
RTL                :    IF N=1 THEN PC <- PC + RRR ELSE PC <- PC + 1
Flags set          :    None

Jump if last arithmetic instruction generated a negative result i.e. jump is conditional on the status register’s N flag. The bit field RRR is as defined in figure 2. In this example RRR is the relative offset 5, if N=1 the PC is set to the value PC+5 at the end of the execution phase, else PC+1. Note, status register (N flag) is only updated by arithmetic functions.

Jumpp

Example            :    jumpc 500
Addressing mode    :    direct
Opcode             :    1001 + 111
RTL                :    IF P=1 THEN PC <- PC + RRR ELSE PC <- PC + 1
Flags set          :    None

Jump if last arithmetic instruction generated a positive result i.e. jump is conditional on the status register’s P flag. The bit field RR is as defined in figure 2. In this example RRR is the relative offset -12, if P=1 the PC is set to the value PC-12 at the end of the execution phase, else PC+1. Note, status register (P flag) is only updated by arithmetic functions.

Cmp
Example            :    cmp RC 33
Addressing mode    :    immediate
Opcode             :    1010 + 00
RTL                :    RX - ( (K7)8 || KK )
Flags set          :    Z,C,O,P,N

Subtract signed 8bit value from general purpose register. The bit field KK is as defined in figure 2. In this example RX is register RC and KK is the value 33, signed extended to 16bits. Therefore, if RC=5 at the end of the execution phase register RC=5, Z=0, C=0, P=0, N=1.

Test

Example            :    test RD 4
Addressing mode    :    immediate
Opcode             :    1010 + 01
RTL                :    RX & ( (0)8 || KK )
Flags set          :    Z,C,O,P,N

Perform 8bit bitwise AND on general purpose register. The bit field KK is as defined in figure 2. In this example RX is register RD and KK is the value 4. Therefore, if RD=7 at the end of the execution phase register RD=7, Z=0, C=0, P=1, N=0. Note, as the value KK represents a binary pattern this data is not sign extended.

Mulu

Example            :    mulu RB 55
Addressing mode    :    absolute
Opcode             :    1011
RTL                :    RX <- RX * ( (0)8 || KK )
Flags set          :    Z,C,O,P,N

Multiply an 8bit unsigned value on a general purpose register. The bit field KK is as defined in figure 2. In this example RX is register RB and KK is the value 55, high byte set to 0 to produce 16bit operand. Therefore, if RB=10 at the end of the execution phase register RD=550. Note, the value KK value is limited to an 8bit unsigned value, producing an 16bit result.

Addmc

Example            :    addmc RA 345
Addressing mode    :    absolute
Opcode             :    1100
RTL                :    RA <- RA + M[AAA] + carry_flag
Flags set          :    Z,C,O,P,N

Add 16bit value stored in memory + carry_flag (C) to general purpose register RA. The bit field AAA is as defined in figure 2. In this example AAA is the address 345, therefore, if RA=20, M[345]=10 and C=1 at the end of the execution phase register RA=31. Note, the destination register is hardwired to register RA, you can not use other registers.

Submc

Example            :    submc RA 456
Addressing mode    :    absolute
Opcode             :    1101
RTL                :    RA <- RA - M[AAA] - carry_flag
Flags set          :    Z,C,O,P,N

Subtract 16bit value stored in memory from general purpose register RA. The bit field AAA is as defined in figure 2. In this example AAA is the address 456, therefore, if RA=20, M[456]=10 and C=1 at the end of the execution phase register RA=9. Note, the destination register is hardwired to register RA, you can not use other registers.

Call

Example            :    call 300
Addressing mode    :    direct
Opcode             :    1110
RTL                :    STACK[SP]<- PC + 1
                   :    SP <- SP + 1
                   :    PC <- AAA
Flags set          :    None

Call subroutine. The bit field AAA is as defined in figure 2. In this example AAA is the address 300, at the end of the execution phase the PC is updated to 300. Note, CALL-RET stack memory is implemented in a separate memory space i.e. LIFO buffer, with integrated stack pointer (SP), max depth of 4.

Ret

Example            :    ret
Addressing mode    :    direct
Opcode             :    1111 + 00000
RTL                :    SP <- SP - 1    
                   :    PC <- STACK[SP]
Flags set          :    None

Return from subroutine. At the end of the execution phase the PC will be updated to the value on the top of the CALL-RET stack. Note, CALL-RET stack memory is implemented in a separate memory space i.e. LIFO buffer, with integrated stack pointer (SP), max depth of 4.

Move

Example            :    move ra rb
Addressing mode    :    register
Opcode             :    1111 + 00001
RTL                :    RX <- RY
Flags set          :    None

Transfer a 16bit value from source to destination general purpose register. Higher and lower opcode values as defined in figure 2. In this example RX is register RA and RY is register RB, therefore, if RB=1 and RA=100 at the end of the execution phase register RA=1.

Load

Example            :    load ra (rb)
Addressing mode    :    register indirect
Opcode             :    1111 + 00010
RTL                :    RX <- M[RY]
Flags set          :    None

Transfer a 16bit value from memory to destination general purpose register. Accessed memory address stored in register enclosed by brackets. Higher and lower opcode values as defined in figure 2. In this example RX is register RA and RY is register RB, therefore, if RB=100 and M[100]=5 at the end of the execution phase register RA=5.

Store

Example            :    store rb (rc)
Addressing mode    :    register indirect
Opcode             :    1111 + 00011
RTL                :    M[RY] <- RX
Flags set          :    None

Transfer a 16bit value from general purpose register to memory. Accessed memory address stored in register enclosed by brackets. Higher and lower opcode values as defined in figure 2. In this example RX is register RB and RY is register RC, therefore, if RB=10 and RC=100 at the end of the execution phase memory location M[100]=10.

rol

Example            :    rol rb
Addressing mode    :    register
Opcode             :    1111 + 00100
RTL                :    RX <- ( RX(14:0) || RX(15) )
                   :    C <- RX(15)
Flags set          :    Z,C,O,P,N

Rotate bits within general purpose register one position to the left. Higher and lower opcode values as defined in figure 2. In this example RX is register RB, therefore, if RB=2, at the end of the execution phase register RB=4.

ror

Example            :    ror rb
Addressing mode    :    register
Opcode             :    1111 + 00101
RTL                :    RX <- ( C || RX(15:1) )
                   :    C <- RX(0)
Flags set          :    Z,C,O,P,N

Rotate bits within general purpose register one position to the right. Higher and lower opcode values as defined in figure 2. In this example RX is register RB, therefore, if RB=2, at the end of the execution phase register RB=1.

Add

Example            :    add ra rb
Addressing mode    :    register
Opcode             :    1111 + 00110
RTL                :    RX <- RX + RY
Flags set          :    Z,C,O,P,N

Add 16bit source general purpose register to destination general purpose register. Not implemented. Higher and lower opcode values as defined in figure 2. In this example RX is register RA and RY is register RB, therefore, if RA=20 and RB=10 at the end of the execution phase register RA=30.

Sub

Example            :    sub ra rb
Addressing mode    :    register
Opcode             :    1111 + 00111
RTL                :    RX <- RX - RY
Flags set          :    Z,C,O,P,N

Subtract 16bit source general purpose register from destination general purpose register. Not implemented. Higher and lower opcode values as defined in figure 2. In this example RX is register RA and RY is register RB, therefore, if RA=25 and RB=10 at the end of the execution phase register RA=15.

And

Example            :    and ra rb
Addressing mode    :    register
Opcode             :    1111 + 01000
RTL                :    RX <- RX & RY
Flags set          :    Z,C,O,P,N

Perform bitwise AND on 16bit source and destination general purpose registers. Not implemented. Higher and lower opcode values as defined in figure 2. In this example RX is register RA and RY is register RB, therefore, if RA=15 and RB=7 at the end of the execution phase register RA=7.

Or

Example            :    or ra rb
Addressing mode    :    register
Opcode             :    1111 + 01001
RTL                :    RX <- RX | RY
Flags set          :    Z,C,O,P,N

Perform bitwise OR on 16bit source and destination general purpose registers. Not implemented. Higher and lower opcode values as defined in figure 2. In this example RX is register RA and RY is register RB, therefore, if RA=15 and RB=7 at the end of the execution phase register RA=15.

Xor

Example            :    xor ra rb
Addressing mode    :    register
Opcode             :    1111 + 01010
RTL                :    RX <- RX | RY
Flags set          :    Z,C,O,P,N

Perform bitwise XOR on 16bit source and destination general purpose registers. Not implemented. Higher and lower opcode values as defined in figure 2. In this example RX is register RA and RY is register RB, therefore, if RA=15 and RB=7 at the end of the execution phase register RA=8.

asl

Example            :    asl rb
Addressing mode    :    register
Opcode             :    1111 + 01011
RTL                :    RX <- ( RX(14:0) || 0 )
                   :    C <- RX(15)
Flags set          :    Z,C,O,P,N

Arithmetic shft bits within general purpose register one position to the left, 0 moved into LSB. MSB moved into C flag. Higher and lower opcode values as defined in figure 2. In this example RX is register RB, therefore, if RB=2 at the end of the execution phase register RB=4 and C=0.

asr

Example            :    asr rb
Addressing mode    :    register
Opcode             :    1111 + 01100
RTL                :    RX <- ( 0 || RX(15:1) )
                   :    C <- RX(0)
Flags set          :    Z,C,O,P,N

Arithmetic shift bits within general purpose register one position to the right, 0 moved into MSB. LSB moved into C flag. Higher and lower opcode values as defined in figure 2. In this example RX is register RB, therefore, if RB=3 at the end of the execution phase register RB=1 and C=1

shl

Example            :    shl rb
Addressing mode    :    register
Opcode             :    1111 + 01101
RTL                :    RX <- ( RX(14:0) || C )
                   :    C <- RX(15)
Flags set          :    Z,C,O,P,N

Shft bits within general purpose register one position to the left, carry flag (C) moved into LSB. MSB moved into C flag. Higher and lower opcode values as defined in figure 2. In this example RX is register RB, therefore, if RB=2 and C=1 at the end of the execution phase register RB=5 and C=0.

shr

Example            :    shr rb
Addressing mode    :    register
Opcode             :    1111 + 01110
RTL                :    RX <- ( C || RX(15:1) )
                   :     C <- RX(0)
Flags set          :    Z,C,O,P,N

Shift bits within general purpose register one position to the right, carry flag (C) moved into MSB. LSB moved into C flag. Higher and lower opcode values as defined in figure 2. In this example RX is register RB, therefore, if RB=3 and C=1 at the end of the execution phase register RB=0x8001 and C=1

Addc

Example            :    addc RB RC
Addressing mode    :    register
Opcode             :    1111 + 01111
RTL                :    RX <- RX + RY + carry_flag
Flags set          :    Z,C,O,P,N

Add general purpose register + carry_flag (0/1) to general purpose register. In this example RX is register RB and RY is RC. Therefore, if RB=1, RC=1 and C=1, at the end of the execution phase register RB=3.

Subc

Example            :    subc RC RD
Addressing mode    :    register
Opcode             :    1111 + 10000
RTL                :    RX <- RX - RY - carry_flag
Flags set          :    Z,C,O,P,N

Subtract general purpose register + carry_flag (0/1) from general purpose register. In this example RX is register RC and RY is register RD. Therefore, if RC=5, RD=2 and C=1 at the end of the execution phase register RC=2.

Cmp
Example            :    cmp RA RB
Addressing mode    :    register
Opcode             :    1111 + 10001
RTL                :    RX - RY
Flags set          :    Z,C,O,P,N

Subtract general purpose register from general purpose register. In this example RX is register RA and RY is register RB. Therefore, if RA=5 and RB=4 at the end of the execution phase register RC=5, Z=0, C=0, P=0, N=1.

Test

Example            :    test RD RB
Addressing mode    :    register
Opcode             :    1111 + 10010
RTL                :    RX & RY
Flags set          :    Z,C,O,P,N

Perform bitwise AND on two general purpose register. In this example RX is register RD and RY is register RB. Therefore, if RD=7 and RB=8 at the end of the execution phase register RD=7, Z=1, C=0, P=1, N=0.

Mulu

Example            :    mulu RB RA
Addressing mode    :    register
Opcode             :    1111 + 10011
RTL                :    RX <- RX * RY
Flags set          :    Z,C,O,P,N

Multiply 8bit unsigned values in two general purpose registers. In this example RX is register RB and RY is register RA. Therefore, if RB=10 and RA=10, at the end of the execution phase register RB=100. Note, operands are limited to 8bit unsigned values, producing an 16bit result.

Common programming constructs

IF Variable = Constant

Pseudo Code             Assembler code                Notes
IF A=0                  start:                        variable A is stored in register
THEN                        test RA 0xFF              RA and is 8bits. Variable B is 
    B = 10                  jumpz zero                stored in RB and is 8bits.
ELSE                    notZero:                    
    B = 20                  move rb 20
END IF                      jump exit
                        zero:
                            move rb 10
                        exit:
                            jump exit

IF Variable = Variable

Pseudo Code             Assembler code                Notes
IF A=B                  start:                        variable A is stored in register 
THEN                       cmp RA 100                 RA, variable B is stored in M[100] 
    C = 10                 jumpz equal                and variable C is stored in M[101]
ELSE                    notEqual:                    
    C = 20                 move RA 20
END IF                     store RA 101
                           jump exit
                        equal:
                           move RA 10
                           store RA 101
                        exit:
                           jump exit

IF Variable < Variable

Pseudo Code             Assembler code                Notes
IF A<B                  start:                      variable A is stored in register   
THEN                        cmp RA 100                RA, variable B is stored in M[100] 
    C = 10                  jumpn less                and variable C is stored in M[101]
ELSE                      greater:                   
    C = 20                  move RA 10
END IF                      store RA 101
                            jump exit
                          less:  
                            move RA 20
                            store RA 101
                        exit:
                            jump exit

FOR Loop

Pseudo Code                 Assembler code                Notes
FOR I in {0..4}             start:                        variable I is stored in 
DO                              move RD 4                 register RD and variable A
    A = A + 1                   move RA 0                 in register RA. Loop count is 
DONE                        loop:                         an 8bit value.
                                and RD 0xFF
                                jumpz exit
                                add RA 1
                                sub RD 1
                                jump loop
                            exit:
                                jump exit

WHILE Loop

Pseudo Code                  Assembler code                Notes
WHILE (A<10)                 start:                        variable RA stored in register
DO                              move RA 0                  RA and is an 8bit value.
    A = A + 1                loop:
DONE                            cmp RA 10
                                jumpz exit
                                add RA 1
                                jump loop    
                            exit:
                                jump exit   

VARIABLES

Pseudo Code                 Assembler code                Notes
A = 100                     start:                        move instruction limited to a
B = 1000                        move RA 0x64              signed/unsigned 8bit values. Variables A 
C = 10000                       moveh RB 0x03             and B are stored in registers 
D = 65535                       or RB 0xE8                RA and RB. Variables C and D 
                                moveu RC 0x27
                                asl RC
                                asl RC
                                asl RC
                                asl RC
                                asl RC
                                asl RC
                                asl RC
                                asl RC
                                add RC 0x10
                                store RC C

                            exit:
                                jump exit    

                            C:
                                .data 0
                            D:
                                .data 0xFFFF
Creative Commons Licence

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

Contact email: mike@simplecpudesign.com

Back