8-bit Computer

Instruction Set
Assembly, Machine Code

GitHub

Instruction Set

This table shows every instruction available to programs on the computer, as well as a small description of their functionalities. An "x" in third column indicates that the instruction uses an argument.

RAM[x] denotes the value at memory location x. A and B correspond to the values of the A and B registers, and ACC stands for the accumulator register.

0 0000 0000 HALT Stop the program from running.
0000 0001 LDA x Load RAM[x] into ACC.
0000 0010 STA x Store ACC in RAM[x].
0000 0011 OUT Show ACC on the output display.
4 0000 0100 NO-OP Do absolutely nothing.
0000 0101 MEMREFLD x Load RAM[RAM[x]] into ACC.
0000 0110 A->B Copy the value of A to B.
0000 0111 A->ACC Copy the value of A to ACC.
8 0000 1000 AREFLD Load RAM[A] into ACC.
0000 1001 B->A Copy the value of B to A.
0000 1010 BREFLD Load RAM[B] into ACC.
0000 1011 B->ACC Copy the value of B to ACC.
12 0000 1100 MEMREFST x Store ACC in RAM[RAM[x]].
0000 1101 ACC->A Copy the value of ACC to A.
0000 1110 ACC->B Copy the value of ACC to B.
0000 1111 AREFST Store ACC in RAM[A].
16 0001 0000 ADDR x Add RAM[x] to ACC.
0001 0001 ADDA Add A to ACC.
0001 0010 ADDB Add B to ACC.
0001 0011 BREFST Store ACC in RAM[B].
20 0001 0100 SUBR x Subtract RAM[x] from ACC.
0001 0101 SUBA Subtract A from ACC.
0001 0110 SUBB Subtract B from ACC.
0001 0111 PAGE x Switch the active page to x.
24 0001 1000 JMP x Jump to address x.
0001 1001 JZ x Jump to address x if ZERO is set.
0001 1010 JC x Jump to address x if CARRY is set.
0001 1011 PUSH Push ACC to the top of the stack.
28 0001 1100 POP Pop the top of the stack into ACC.
0001 1101 CALL x Call the function at address x.
0001 1110 RETURN Return from the current function.

Assembly and Machine Code

Programs are either written in assembly language or machine code. The machine code, when placed in RAM, begins execution at memory address 0. Then, every instruction takes up two bytes: one for the opcode and one for the argument. If no argument is required for a particular instruction, anything can be used, but 0 is common.

Assembly also uses a very simple format. A typical assembly program might look like this:

	LDA	50	Push two numbers, 1 and 2, to the stack.
	PUSH
	LDA	51
	PUSH
	LDA	52	Clear the accumulator.
	POP	0	Then, pop and output the two numbers.
	OUT	0	They should be displayed in reverse order.
	POP
	OUT
	HALT
	
50	DATA	1
51	DATA	2
52	DATA	0

The first column is the address of the instruction or data. The second column is the mnemonic of the instruction to execute. The third column is the argument to that instruction. And, any text after the third column is considered a comment and ignored. Additionally, the first and third