The CPU simulator implements a simple 16-bit architecture with the following features:
Instruction | Opcode | Description |
---|---|---|
HALT |
0x0 | Stop program execution |
LOAD value |
0x1 | Load immediate value into ACC |
LOADM addr |
0x2 | Load value from memory into ACC |
STORE addr |
0x3 | Store ACC to memory |
ADD value |
0x4 | Add immediate value to ACC |
ADDM addr |
0x5 | Add memory value to ACC |
SUB value |
0x6 | Subtract immediate value from ACC |
SUBM addr |
0x7 | Subtract memory value from ACC |
JUMP addr |
0x8 | Jump to address |
JUMPZ addr |
0x9 | Jump if ACC is zero |
JUMPNZ addr |
0xA | Jump if ACC is not zero |
; Count from 0 to 255 LOAD 0 ; Initialize counter loop: STORE 100 ; Store current value ADD 1 ; Increment JUMPNZ loop; Continue if not zero HALT
; Copy memory from address 50 to 100 LOAD 10 ; Number of values to copy STORE 0 ; Store counter loop: LOADM 50 ; Load from source STORE 100 ; Store to destination LOAD 1 ADD 50 ; Increment source address STORE 50 LOAD 1 ADD 100 ; Increment destination address STORE 100 LOADM 0 ; Load counter SUB 1 ; Decrement counter STORE 0 ; Store updated counter JUMPNZ loop; Continue if counter not zero HALT
label:
); comment
)The memory consists of 256 16-bit words (addresses 0-255). There are no reserved memory locations, and the program can use any memory address for data storage.