Skip to content

Instruction Set

Gil Keidar edited this page Nov 20, 2022 · 8 revisions

The ByteFrost computer uses a RISC-inspired instruction set. Currently, it is designed to have a maximum of 32 different opcodes (hence opcodes take 5 bits in an instruction). Each instruction is composed of 2 bytes.

Each instruction must specify the opcode to be used (the opcode goes in the 5 least-significant bits of the first byte of an instruction), and can specify a destination register, a maximum of two source registers, and / or an immediate. There are other variations specific to particular instructions, but these are the general constraints. To simplify hardware implementation, the instructions are structured as similar to each other as possible - for instance, the location of the destination register (Rd) will always be in bits 6 and 7 of the overall instruction.

Here are two general instruction skeletons that illustrates this structure:

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Rs2 Rs1 X X X X Rd X Opcode
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
8-bit immediate Rd X Opcode

A list of currently implemented instructions follows:

Opcode Instruction Use Assembly Syntax Sets Flags Structure
0 NOP No operation NOP No 0x00 0x00
1 BRK Halts operation BRK No 0x01 0x00
2 ALU Use ALU to modify values in two input registers
and store output in a register
(ALU function) Rd, Rs1, Rs2 Yes [Rd X 00010] [Rs2 Rs1 Function select]
3 LDR Load immediate value to a register LDR Rd, #Imm No [Rd X 00011] [ 8-bit immediate]
4 MOV Copy value in one register to another MOV Rd, Rs1 No [Rd X 00100] [XX Rs1 XXXX]
5 Branch immediate Conditionally sets program counter
to an immediate value
(Branch condition) #Imm No [Condition 00101] [8-bit immediate]
6 ALU immediate Use ALU taking the value of a source
register and an immediate, then setting the
source register to the new value
(ALU function) Rd, #Imm Yes [Rd X 00110] [4-bit immediate Function select]
7 Branch relative Conditionally adds an immediate value to
the program counter and sets the program
counter to the new value
(Branch condition) +/-Imm No [Condition 00111] [8-bit immediate]
8 OUT Prints value of a register to the display
(can print the int value as is or the ASCII character)
OUT Rs1, A/I No [XX A/I 01000] [XX Rs1 XXXX]
9 LMA Load a value from memory at a given address to a register LMA Rd, #Imm No [Rd X 01001] [8-bit immediate]
A SMA Store a value in a register to memory at a given address SMA Rd, #Imm No [Rd X 01010] [8-bit immediate]
B LMR Load a value from memory at an address stored in a register to another register LMR Rd, Rs1 No [Rd X 01011] [XX Rs1 XXXX]
C SMR Store a value in a register to memory at an address stored in another register SMR Rd, Rs1 No [Rd X 01100] [XX Rs1 XXXX]
D OUT immediate Prints an immediate value to the display
(can print the int value as is or the ASCII character)
OUT #Imm, A/I No [XX A/I 01101] [8-bit immediate]
E PUSH Store a value in a register to the stack and increment stack pointer PUSH Rs1 No [XXX 01110] [XX Rs1 XXXX]
F POP Decrement stack pointer and retrieve value from the stack to a register POP Rd No [Rd X 01111] [XXXX XXXX]
10 JSR Jump to subroutine (store next program address on the stack) JSR #Imm No [XXX 10000] [8-bit immediate]
11 RTS Return from subroutine (load PC with return address on the stack) RTS No [XXX 10001] [XXXX XXXX]
12 TEST Use ALU to modify values in two input registers
but doesn't save output
(used to update flags)
COMP Rs1, Rs2 Yes [XXX 10010] [Rs2 Rs1 Function select]
13 TEST immediate Use ALU to modify values in an input register and
immediate but doesn't save output
(used to updated flags)
COMP Rs1, #Imm or TST Rs1 Yes [XXX 10011] [4-bit immediate Function select]
Clone this wiki locally