GP2X Emulation Tutorial


SirDzstic

Member
Joined
Nov 14, 2005
Messages
187
I wrote a very tiny emulator, to help understanding, how emulation
works.

It emulates a CPU, that only understands 5 instructions, but can
run programs. I included two example programs and an assembler,
which can create binaries for the emulator from the included source
code.

The sample programs are found in the directory examples and may
be assembled using "make examples".

When the emulator runs, it looks like this:
asdf@localh0rst ~/src/aisc-0.0.1 $ bin/aisc bin/add-2.aisc 1 2
0 JMP 6 1 2 0 0 0 0 0 0
6 ISZ 1 1 2 0 0 0 0 0 0
8 JMP 2 1 2 0 0 0 0 0 0
2 INC 0 2 2 0 0 0 0 0 0
4 DEC 1 2 1 0 0 0 0 0 0
6 ISZ 1 2 1 0 0 0 0 0 0
8 JMP 2 2 1 0 0 0 0 0 0
2 INC 0 3 1 0 0 0 0 0 0
4 DEC 1 3 0 0 0 0 0 0 0
6 ISZ 1 3 0 0 0 0 0 0 0
10 STP 3 0 0 0 0 0 0 0

It will take an assembled binary as the first argument, and after that
up to 8 initial values for the 8 CPU-registers (which are limited to 8
bits, so there is a maximum value of 255 for each register).
The sample program add-2 adds the values in registers 0 and 1
(which are initialised to 1 and 2 above) and saves the sum in
register 0. In the last line of the quote, you'll see the 3 :)

The output means the following:
In the first column is the address, to which the program counter points.
Columns 2 and 3 are the current opcode and argument. The other columns
are the values inside the 8 registers.

The CPU understands the following 5 instructions:
"STP": Stop execution
"JMP x": Jump to address x
"DEC x": Increase the value inside register x by 1
"INC x": Decrease the value inside register x by 1
"ISZ x": If register x has the value 0, skip the next instruction.

I hope, this is helpful to anybody ;)

DOWNLOAD :E
 
Back
Top