Introduction

This simulator provides a simplified assembler syntax (based on TEXT BOOK "Computer Science: An Overview") and is simulating a 8-bit cpu.

The simulator consists of a 8-bit cpu and 256 bytes of memory. All instructions (code) and variables (data) needs to fit inside the memory. For simplicity every instruction (and operand) is 2 byte.

Syntax

The syntax is similar as most assemblers are using. Every instruction must be on their own line. Labels are optional and must either start with a letter or a dot (.) and end with a colon.

label: instruction operands	; Comment

Valid number formats for constants are:

Decimal: 200
Hex: 0xA4

It is possible to define a number using a character or multiple numbers (see instruction DB) by using a string.

Character: 'A'
String: "Hello World!"

Operands can either be one of the 16 general purpose registers, a memory address or a constant. Instead of defining an address as a constant or by using a register you can use labels. The assembler will then replace the label with the corresponding constant.

General purpose (GP) register: R0-RE
Timer interrupt register: RF
Address using a constant: 100
Address using a label: label

MOVE S, R

MOVE the bit pattern found in register R to register S.

MOVE reg, reg

DB - Variable

Defines a variable. A variable can either be a single number, character or a string.

DB constant

integer/float Addition

Adds two numbers together.

ADDI regR, regS, regT ; regR=regS+regT integer
ADDF regR, regS, regT ; regR=regS+regT float
Logical instructions

The following logical instructions are supported: AND, OR, XOR.

AND regR, regS, regT ; R=S & T
OR  regR, regS, regT ; R=S | T
XOR regR, regS, regT ; R=S ^ T
Shift instructions

The following shift instructions are supported: ROTATE to right.

ROT regR, numX  ; regR=regR rotate-right numX times

JUMP - jump if equal

JUMP to the instruction located in the memory cell at address XY if the bit pattern in register R is equal to the bit pattern in register 0. Otherwise, continue with the normal sequence of execution. (The jump is implemented by copying XY into the program counter during the execute phase.)

JUMP regR, numXY

JUMPL - jump if less

JUMPL to the instruction located in the memory cell at address XY if the bit pattern in register R is less than the bit pattern in register 0. Otherwise, continue with the normal sequence of execution. (The jump is implemented by copying XY into the program counter during the execute phase.)

JUMPL regR, numXY

HALT

Stops operation of the processor. Hit Reset button to reset IP before restarting.

HALT

LOADM (Load from Memory)

LOAD the register R with the bit pattern found in the memory cell whose address is XY.

LOADM regR, numXY

LOADB (Load with Bit Pattern)

LOAD the register R with the bit pattern XY.

LOADB regR, numXY

LOADP (Load via Pointer)

LOAD the register R with the contents of the memory cell whose address is found in register S.

LOADP regR, regS

STOREM (Store to Memory)

STORE the bit pattern found in register R in the memory cell whose address is XY.

STOREM regR, numXY

STOREP (Store via Pointer)

STORE the contents of register R in the memory cell whose address is found in register S.

STOREP regR, regS

by Yuanchun Shi, Yu Chen, Junjie Mao, Yukang Yan (2015) | MIT License | Source Code

by Marco Schweighauser (2015) | MIT License | Blog