blossoms75 wrote
Are there any other things you've found helpful in debugging the assembly code?
Another trick I've seen several people use is to write recognizable @ instructions at the beginning of the ASM for each VM statement. This makes it easier to find the start of the sequences in CPU Emulator's disassembly list.
@11111
@SP
AM=M-1
...
This also lets you set a "next VM command" breakpoint by breaking on A=11111.
After the @11111 you can write other numbers that can write other numbers that can be used to trigger breakpoints. For instance, you might want to be able to trigger on all 'return' statements so you could write an @22222 for returns.
To be able to find the ASM based on VM source line numbers, add something like @2nnnn.
You will want to have an easy way to turn these extra commands on and off, like a global variable at the beginning of your translator.
More work, but handy to have is to retrofit your Assembler to generate a listing file that shows the addresses for each instruction.
// This file is part of the materials accompanying the book
// "The Elements of Computing Systems" by Nisan and Schocken,
// MIT Press. Book site: www.idc.ac.il/tecs
// File name: projects/06/max/Max.asm
// Computes M[2] = max(M[0], M[1]) where M stands for RAM
0 0 @0
1 FC10 D=M // D=first number
2 1 @1
3 F4D0 D=D-M // D=first number - second number
4 10 @OUTPUT_FIRST
5 E301 D;JGT // if D>0 (first is greater) goto output_first
6 1 @1
7 FC10 D=M // D=second number
8 12 @OUTPUT_D
9 EA87 0;JMP // goto output_d
10 (OUTPUT_FIRST)
10 0 @0
11 FC10 D=M // D=first number
12 (OUTPUT_D)
12 2 @2
13 E308 M=D // M[2]=D (greatest number)
14 (INFINITE_LOOP)
14 14 @INFINITE_LOOP
15 EA87 0;JMP // infinite loop
(In my listing file, the ROM addresses and @ instruction values are decimal and the instruction values are hexadecimal.)
--Mark