Opcodes for the 9x8 micro controller


Copyright 2012, Sinclair R.F., Inc.

This document describes the opcodes for the 9x8 micro controller. The first section lists the opcodes in alphabetic order, the second lists them by their numerical value, and the final section describes each one in detail.

Some of the opcodes are not directly accessible by the assembler and must be accessed through macros. See macros for documentation on accessing these opcodes. Other opcodes can be directly accessed or can be accessed through a macro.

OPCODES

This section documents the opcodes.

Alphabetic listing: &, +, -, -1<>, -1=, 0<>, 0=, 0>>, 1+>, 1->, 1>>, <<0, <<1, <<msb, >r, ^, call, callc, drop, dup, fetch, fetch+, fetch-, inport, jump, jumpc, lsb>>, msb>>, nip, nop, or, outport, over, push, r>, r@, return, store, store+, store-, swap

Opcode Mapping

Opcode    876543   210    Description
nop 000000000 no operation
<<0 000000001 left shift 1 bit and bring in a 0
<<1 000000010 left shift 1 bit and bring in a 1
<<msb 000000011 left shift 1 bit and rotate the msb into the lsb
0>> 000000100 right shift 1 bit and bring in a 0
1>> 000000101 right shift 1 bit and bring in a 1
msb>> 000000110 right shift 1 bit and keep the msb the same
lsb>> 000000111 right shift 1 bit and rotate the lsb into the msb
dup 000001000 push a duplicate of the top of the data stack onto the data stack
r@ 000001001 push a duplicate of the top of the return stack onto the data stack
over 000001010 push a duplicate of the next-to-top of the data stack onto the data stack
swap 000010010 swap the top and the next-to-top of the data stack
+ 000011000 pop the stack and replace the top with N+T
- 000011100 pop the stack and replace the top with N-T
0= 000100000 replace the top of the stack with "0xFF" if it is "0x00" (i.e., it is zero), otherwise replace it with "0x00"
0<> 000100001 replace the top of the stack with "0xFF" if it is not "0x00" (i.e., it is non-zero), otherwise replace it with "0x00"
-1= 000100010 replace the top of the stack with "0xFF" if it is "0xFF" (i.e., it is all ones), otherwise replace it with "0x00"
-1<> 000100011 replace the top of the stack with "0xFF" if it is not "0xFF" (i.e., it is not all ones), otherwise replace it with "0x00"
return 000101000 return from a function call
inport 000110000 replace the top of the stack with the contents of the specified input port
outport 000111000 write the next-to-top of the data stack to the output port specified by the top of the data stack
>r 001000000 Pop the top of the data stack and push it onto the return stack
r> 001001001 Pop the top of the return stack and push it onto the data stack
& 001010000 pop the stack and replace the top with N & T
or 001010001 pop the stack and replace the top with N | T
^ 001010010 pop the stack and replace the top with N ^ T
nip 001010011 pop the next-to-top from the data stack
drop 001010100 drop the top value from the stack
1+ 001011000 Add 1 to T
1- 001011100 Subtract 1 from T
store 0011000bb Store N in the T'th entry in bank "bb", drop the top of the data stack
fetch 0011010bb Exchange the top of the stack with the T'th value from bank "bb"
store+ 0011100bb Store N in the T'th entry in bank "bb", nip the data stack, and increment T
store- 0011101bb Store N in the T'th entry in bank "bb", nip the data stack, and decrement T
fetch+ 0011110bb Push the T'th entry from bank "bb" into the data stack as N and increment T
fetch- 0011111bb Push the T'th entry from bank "bb" into the data stack as N and decrement T
jump 0100xxxxx Jump to the address "x_xxxx_TTTT_TTTT"
jumpc 0101xxxxx Conditionally jump to the address "x_xxxx_TTTT_TTTT"
call 0110xxxxx Call the function at address "x_xxxx_TTTT_TTTT"
callc 0111xxxxx Conditionally call the function at address "x_xxxx_TTTT_TTTT"
push 1xxxxxxxx Push the 8-bit value "xxxx_xxxx" onto the data stack.

Detailed Descriptions

Instruction: &

Desription: Pop the data stack and replace the top with the bitwise and of the previous top and next-to-top.

Operation:

PC ← PC+1
R and return unchanged
T ← T & N
N ← stack--

Instruction: +

Desription: Pop the data stack and replace the top with the 8 sum of the previous top and next-to-top.

Operation:

PC ← PC+1
R and return unchanged
T ← N + T
N ← stack--

Instruction: -

Desription: Pop the data stack and replace the top with the 8 difference of the previous top and next-to-top.

Operation:

PC ← PC+1
R and return unchanged
T ← N - T
N ← stack--

Instruction: -1<>

Desription: Set the top of the stack to all ones if the previous value was not all ones, otherwise set it to all zeros.

Operation:

PC ← PC+1
R and return unchanged
T ← 0xFF if T!=0xFF, 0x00 otherwise
N and stack unchanged

Instruction: -1=

Desription: Set the top of the stack to all ones if the previous value was all ones, otherwise set it to all zeros.

Operation:

PC ← PC+1
R and return unchanged
T ← 0xFF if T=0xFF, 0x00 otherwise
N and stack unchanged

Instruction: 0<>

Desription: Set the top of the stack to all ones if the previous value was not all zeros, otherwise set it to all zeros.

Operation:

PC ← PC+1
R and return unchanged
T ← 0xFF if T!=0x00, 0x00 otherwise
N and stack unchanged

Instruction: 0=

Desription: Set the top of the stack to all ones if the previous value was all zeros, otherwise set it to all zeros.

Operation:

PC ← PC+1
R and return unchanged
T ← 0xFF if T=0x00, 0x00 otherwise
N and stack unchanged

Instruction: 0>>

Desription: Right shift the top of the stack one bit, replacing the left-most bit with a zero.

Operation:

PC ← PC+1
R and return unchanged
T ← { 0, T[7], T[6], ..., T[1] }
N and stack unchanged

Instruction: 1+

Desription: Add 1 to T.

Operation:

PC ← PC+1
R and return unchanged
T ← T+1
N and stack unchanged

Instruction: 1-

Desription: Subtract 1 from T.

Operation:

PC ← PC+1
R and return unchanged
T ← T-1
N and stack unchanged

Instruction: 1>>

Desription: Right shift the top of the stack one bit, replacing the left-most bit with a zero.

Operation:

PC ← PC+1
R and return unchanged
T ← { 1, T[7], T[6], ..., T[1] }
N and stack unchanged

Instruction: <<0

Desription: Left shift the top of the stack one bit, replacing the right-most bit with a zero. Operation:

PC ← PC+1
R and return unchanged
T ← { T[6], T[5], ..., T[0], 0 }
N and stack unchanged

Instruction: <<1

Desription: Left shift the top of the stack one bit, replacing the right-most bit with a one.
Operation:

PC ← PC+1
R and return unchanged
T ← { T[6], T[5], ..., T[0], 1 }
N and stack unchanged

Instruction: <<msb

Desription: Left shift the top of the stack one bit, leaving the right-most bit unchanged.

Operation:

PC ← PC+1
R and return unchanged
T ← { T[6], T[5], ..., T[0], T[7] }
N and stack unchanged

Instruction: >r

Desription: Pop the data stack and push its previous value onto the return stack.

Operation:

PC ← PC+1
R ← T
++return ← R
T ← N
N ← stack--

Instruction: ^

Desription: Pop the data stack and replace the top with the bitwise exclusive or of the previous top and next-to-top.

Operation:

PC ← PC+1
R and return unchanged
T ← T ^ N
N ← stack--

Instruction: call

Desription: Call the function at the address constructed from the opcode and T. Discard T and push the PC onto the return stack.

Operation:

PC ← { O[4], ..., O[0], T[7], T[6], ..., T[0] }
R ← PC+1
++return ← R
T ← N
N ← stack--

Special:

Interrupts are disabled during the clock cycle immediately following a call instruction.

The assembler normally places a "nop" instruction immediately after the "call" instruction.

Instruction: callc

Desription: Conditionally call the function at the address constructed from the opcode and T. Discard T and conditionally push the next PC onto the return stack.

Operation:

if N != 0 then
  PC ← { O[4], ..., O[0], T[7], T[6], ..., T[0] }
  R ← PC
  ++return ← R
else
  PC ← PC+1
  R and return unchanged
endif
T ← N
N ← stack--

Special:

Interrupts are disabled during the clock cycle immediately following a callc instruction.

The assembler normally places a "drop" instruction immediately after the "callc" instruction.

Instruction: drop

Desription: Pop the data stack, discarding the value that had been on the top.

Operation:

PC ← PC+1
R and return unchanged
T ← N
N ← stack--

Instruction: dup

Desription: Push the top of the data stack onto the data stack.

Operation:

PC ← PC+1
R and return unchanged
T ← T
N ← T
++stack ← N

Instruction: fetch

Desription: Replace the top of the data stack with an 8 bit value from memory. The memory bank is specified by the two least-significant bits of the opcode. The index within the memory bank is specified by the previous value of the top of the stack.

Operation:

PC ← PC+1
R and return unchanged
T ← bb[T] where "bb" is the bank
N and stack unchanged
Special: See memory for instructions on using the fetch and vectorized fetch macros.

Instruction: fetch+

Desription: Push the T'th entry from bank "bb" onto the data stack as N and increment the top of the data stack.

Operation:

PC ← PC+1
R and return unchanged
T ← T+1
N ← bb[T] where "bb" is the bank
++stack
Special: See memory for instructions on using the fetch and vectorized fetch macros.

Instruction: fetch-

Desription: Push the T'th entry from bank "bb" onto the data stack as N and decrement the top of the data stack.

Operation:

PC ← PC+1
R and return unchanged
T ← T-1
N ← bb[T] where "bb" is the bank
++stack
Special: See memory for instructions on using the fetch and vectorized fetch macros.

Instruction: inport

Desription: Replace the top of the data stack with the 8 value from the port specified by the previous value of the top of the data stack.

Operation:

PC ← PC+1
R and return unchanged
T ← input_port[T]
N and stack unchanged

Special:

The recommended procedure to read from an inport port is to use the ".inport" macro.

Instruction: jump

Desription: Jump to the address constructed from the opcode and T. Discard T.

Operation:

PC ← { O[4], ..., O[0], T[7], T[6], ..., T[0] }
R and return unchanged
T ← N
N ← stack--

Special:

Interrupts are disabled during the clock cycle immediately following a jump instruction.

The assembler normally places a "nop" instruction immediately after the "jump" instruction.

Instruction: jumpc

Desription: Jump to the address constructed from the opcode and T if N is non-zero. Discard S and N.

Operation:

if N != 0 then
  PC ← { O[4], ..., O[0], T[7], T[6], ..., T[0] }
else
  PC ← PC+1
end if
R and return unchanged
T ← N
N ← stack--

Special:

Interrupts are disabled during the clock cycle immediately following a jumpc instruction.

The assembler normally places a "drop" instruction immediately after the "jump" instruction so that the conditional is dropped from the data stack.

Instruction: lsb>>

Desription: Right shift the top of the stack one bit, replacing the left-most bit with the previous value of the right-most bit.

Operation:

PC ← PC+1
R and return unchanged
T ← { T[0], T[7], T[6], ..., T[1] }
N and stack unchanged

Instruction: msb>>

Desription: Right shift the top of the stack one bit, preserving the value of the left-most bit.

Operation:

PC ← PC+1
R and return unchanged
T ← { T[7], T[7], T[6], ..., T[1] }
N and stack unchanged

Instruction: nip

Desription: Discard the next-to-top value on the data stack.

Operation:

PC ← PC+1
R and unchanged
T ← T
N ← stack--

Instruction: nop

Desription: No operation.

Operation:

PC &leftarrow PC + 1
R, return, T, N, and stack unchanged

Instruction: or

Desription: Pop the data stack and replace the top with the bitwise or of the previous top and next-to-top.

Operation:

PC ← PC+1
R and return unchanged
T ← T or N
N ← stack--

Instruction: outport

Desription: Pop the data stack and write the previous next-to-top to the port specified by the previous top.
Operation:

PC ← PC+1
R and return unchanged
T ← N
N ← stack--
outport[T] ← N

Special:

This instruction must be following by a "drop" in order to discard the value from the data stack that had been written to the data port. The recommended procedure to write to an output port is to use the ".outport" macro.

Instruction: over

Desription: Push the next-to-top of the data stack onto the data stack.

Operation:

PC ← PC+1
R and return unchanged
T ← N
N ← T
++stack ← N

Instruction: push

Description: Push the specified 8-bit value onto the 8-bit stack.

Operation:

PC ← PC+1
R and return unchanged
T ← opcode[7:0]
N ← T
++stack ← N

Instruction: r>

Desription: Pop the return stack and push its previous value onto the data stack.

Operation:

PC ← PC+1
R ← return--
T ← R
N ← T
++stack ← N

Instruction: r@

Desription: Push the top of the return stack onto the data stack.

Operation:

PC ← PC+1
R and return unchanged
T ← R
N ← T
++stack ← N

Instruction: return

Description: Popd the top of the return stack into the PC.

Operation:

PC ← R
R ← return--
T, N, and stack unchanged

Special: This instruction must be followed by a "nop" instruction.

Instruction: store

Desription: Drop the top of the data stack and store the previous next-to-top of the data stack at the memory location specified by the top of the data stack. The memory bank is specified by the two least significant bits of the opcode.

Operation:

PC ← PC+1
R and return unchanged
T ← N
N ← stack--
bb[T] ← N where "bb" is the bank

Special: See memory for instructions on using the store and vectorized store macros.

Instruction: store+

Desription: Nip the data stack and store the previous next-to-top of the data stack at the memory location specified by the top of the data stack. Increment the top of the data stack The memory bank is specified by the two least significant bits of the opcode.

Operation:

PC ← PC+1
R and return unchanged
T ← T+1
N ← stack--
bb[T] ← N where "bb" is the bank

Special: See memory for instructions on using the store and vectorized store macros.

Instruction: store-

Desription: Nip the data stack and store the previous next-to-top of the data stack at the memory location specified by the top of the data stack. Decrement the top of the data stack The memory bank is specified by the two least significant bits of the opcode.

Operation:

PC ← PC+1
R and return unchanged
T ← T-1
N ← stack--
bb[T] ← N where "bb" is the bank

Special: See memory for instructions on using the store and vectorized store macros.

Instruction: swap

Desription: Swap the top two values on the data stack.

Operation:

PC ← PC+1
R and return unchanged
T ← N
N ← T
stack unchanged