How to use cp8299x simulator
command line sim
file.s
The simulator takes object code input file in S-format. It
executes the instructions step by step and shows all the registers and
flags. A jump to subroutine 1001 (JSR 1001) will stop the
simulator.
Limit
The number of instruction executed is limited to 20,000 instructions in
case there is an infinite loop. The memory is 1000 bytes.
The simulator implements a Big Endian representation ( Hi byte
first). When pushing 16 bits value into the stack, Lo byte will
be pushed first then Hi byte (so that the number in the data
segment and stack segment will be ordered in the same way).
The output in trace mode displayed PC, instruction, AC, SP, and
flags. All numbers are in hexadecimal.
The simulator has a simple command line mode, with the following
commands:
- g [go] start executing a the current pc, initially pc = 0
- t [single step] execute one instruction and display
- d ads n [dump DS] dump memory at ads, n bytes
- b ads [set breakpoint] set breakpoint at ads
- c [clear breakpoint] clear breakpoint
- z 1/0 [on/off display] turn on/off display
- q [quit] quit the simulator
- h [help] get help message
Example of a session
This is the sample session of running "asgm1.txt" (the first example in
the lecture). First assemble "asgm1.txt".
c>
asm asgm1.txt
this will generate two files: asgm1.lst and asgm1.s
Here is asgm1.lst
0000
: 4C 0100 jmp begin
a: 0
b: 10
c: 20
begin:
0100 : 1C 0004
lda b ;; lda direct
0103 : CC 0005
add c
0106 : 3C 0003
sta a
0109 : 7C 03E9
jsr 1001
It shows the address on the left, and the opcode and operand, then the
source line.
Start the simulator with the object code "asgm1.s"
c>
sim asgm1.s
We will single step through the whole program. When it finished
by executing "jsr 1001", the simulator prints "stop". Each step the
simulator displays PC, opcode, AC, SP, carry and zero flag (all in hex
numbers). The SP starts at the end of memory and works
downward.
C:\prabhas\BAG\Chip\cp8299x\test>sim
asgm1.s
>t
pc:0000 JMP A:00
SP:03E7 C0 Z0
>t
pc:0100 LDA A:0A
SP:03E7 C0 Z0
>t
pc:0103 ADD A:1E
SP:03E7 C0 Z0
>t
pc:0106 STA A:1E
SP:03E7 C0 Z0
>t
stop
pc:0109 JSR A:1E
SP:03E7 C0 Z0
We inspect the content of memory to see the result of executing the
program. The variable "a" (at address 5) is 1EH (30) which is the
expected result. We exit the simulator by "q".
>d
0 10
0000 : 4C 01 00 1E 0A 14 00 00 00
00
000A : 00 00 00 00 00 00
>q
C:\prabhas\BAG\Chip\cp8299x\test>
There are many examples in the directory "test" will all examples you
found in the class. Enjoy reading and try them out.
Input is not robust, that is, if you type everything correctly, it
works as expect, if you input something wrong, it probably cannot
recover. The simplest way is to restart it. Please report
any bug to me. I will update it as soon as I get the
report. Evenbetter if you fix it yourself and let me know.
The main simulator "cpu5.c" is less than 200 lines long, the command
line interpreter "mon.c" is 100 lines long. Tweak it as you
please. Enjoy!
Prabhas Chongstitvatana
18 December 2005