REGISTERS: [Rx]

This is the list of register mnemonics which can be used in place of [Rx]. All registers are 8-bits.

ADDRESS MODES:

Most instructions take one or two parameters. These can be a register, an address or an immediate value, depending on the instruction.

CPU FLAGS:

Any operation involving the ALU will update the CPU flags as follows:

LABELS:

Labels start with "." (eg. .loop). Labels can be referenced anywhere a {value} or {address} is expected.

.loop:
  inc Rd
  jnz .loop

#addr {addr}

Allows you to set the address of the current line. eg.
#addr 0x80
.myfunc
  ret
Will result in .myfunc being placed in memory at address 0x80 (128).

CONSTANTS:

Define a constant with the syntax NAME = value. Constants can be used in place of values or addresses. eg.

MYVALUE = 3
  data Rd, MYVALUE

INSTRUCTIONS:

Arithmetic operations

add [Rx]

Add Rb to the register [Rx]. Output the result back to [Rx]

addc [Rx]

Add Rb to the register [Rx], inputting the carry flag if set. Output the result back to [Rx]

sub [Rx]

Subtract Rb from the register [Rx]. Output the result back to [Rx]

subc [Rx]

Add Rb to the register [Rx], inputting the carry flag if set. Output the result back to [Rx]

sub Rb, [Rx]

Subtract [register Rx] from Rb. Output the result back to [Rx]

subc Rb, [Rx]

Subtract register [Rx] from Rb, inputting the carry flag if set. Output the result back to [Rx]

inc [Rx]

Increment the value of register [Rx]

dec [Rx]

Decrement the value of register [Rx]

Logic operations

and [Rx]

Logical AND or register [Rx] and Rb. Output the result back to [Rx]

or [Rx]

Logical OR or register [Rx] and Rb. Output the result back to [Rx]

xor [Rx]

Logical EXCLUSIVE-OR or register [Rx] and Rb. Output the result back to [Rx]

not [Rx]

Bitwise-invert register [Rx]. Output the result back to [Rx]

cmp [Rx]

Compare register [Rx] with Rb. Result stored in CPU flags (N if [Rx] less than Rb, Z if [Rx] == Rb)

cmp Rb, [Rx]

Compare Rb with register [Rx]. Result stored in CPU flags (N if Rb less than [Rx], Z if Rb == [Rx])

tst [Rx]

Test value stored in register [Rx]. Result stored in CPU flags (N if [Rx] is less than 0, Z if Rb == [Rx])

lsr

Binary left-shift value stored in Rb.

Flow control

jmp {addr}

Unconditional jump to the address given in {addr}. Updates the program counter for this address to be executed next.

jmp [Rx]

Unconditional jump to the address stored in register [Rx]. Updates the program counter for this address to be executed next.

jmpz

Unconditional jump address 0x00.

jc {addr}

Jump to the address given in {addr} if the CPU carry (C) flag is set. Otherwise, continue.

jn {addr}

Jump to the address given in {addr} if the CPU negative (N) flag is set. Otherwise, continue.

jo {addr}

Jump to the address given in {addr} if the CPU overflow (O) flag is set. Otherwise, continue.

jz {addr}

Jump to the address given in {addr} if the CPU zero (Z) flag is NOT set. Otherwise, continue.

jnc {addr}

Jump to the address given in {addr} if the CPU carry (C) flag is NOT set. Otherwise, continue.

jnn {addr}

Jump to the address given in {addr} if the CPU negative (N) flag is NOT set. Otherwise, continue.

jno {addr}

Jump to the address given in {addr} if the CPU overflow (O) flag is NOT set. Otherwise, continue.

jnz {addr}

Jump to the address given in {addr} if the CPU zero (Z) flag is NOT set. Otherwise, continue.

Registers

mov [dRx], [sRx]

Copy the value stored in register [sRx] to the register [dRx].

mov [dRx], #{value}

Write immediate {value} to the register [dRx].

mv(a|b|c|d) [sRx]

Copy the value stored in register [sRx] to the register (a, b, c or d). eg. mva Rb (Copy contents of Rb to Ra)

mv(a|b|c|d) #{value}

Write immediate {value} to the register (a, b, c or d).

data [dRx], #{value}

Write immediate {value} to the register [dRx].

clr [Rx]

Set the value stored in register [Rx] to zero.

clra

Clear all registers (Ra -> Rd)

Memory

lod [dRx], [sRx]

Load the value from memory address stored in register [sRx] into register [dRx].

lod [dRx], #{value}

Load the value from memory address {value} into register [dRx].

sto [dRx], [sRx]

Store the value from register [sRx] into memory address stored in register [dRx].

sto [dRx], #{value}

Store the value from register [dRx] into memory address {value}.

Stack

push [Rx]

Push the value stored in register [Rx] on to the stack.

push #{value}

Push the {value} on to the stack.

pop [Rx]

Pop the last value from the stack and place it in register [Rx].

pop {addr}

Pop the last value from the stack and place it in memory location {addr}.

peek [Rx]

Place the last value from the stack in register [Rx], however don't update the stack pointer.

peek {addr}

Place the last value from the stack in memory at location {addr}, however don't update the stack pointer.

call

Call the function at the address stored in register Rc. Pushes the current address to the stack and sets the program counter to Rc.

call {addr}

Call the function at the address {addr}. Pushes the current address to the stack and sets the program counter to {addr}. Note: this instruction replaces the contents of Rc.

ret

Return to the address after the last function call. Pops the address from the stack and sets the program counter.

Miscellaneous

nop

No-operation. Do nothing for one instruction.

hlt

Halt. Stops the clock.