Debug pong

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Debug pong

Gabrix
Hello, my vm translator have passed all test (fibonacci,stacktest,ecc...), I have translated the Pong with the OS but I have an error: "At line 5497: Expression involves M but A=24577 is an illegal memory address."
Where is the problem? The file translated is 28000 lines and is impossible to search the problem...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Debug pong

cadet1620
Administrator
This is a really tricky thing to debug.  You message says that the problem occurred at an instruction at ROM address 5497, but finding that instruction is difficult because the line numbers in the Pong.asm file don't match up with ROM addresses because labels don't require ROM locations.

Two things that I suggest are that you have your VM translator write the source VM lines into the ASM output as comments so that it makes it easier to find what the associated VM command is when you find the failing ASM command.  See this post for an example.  Note that I also put a filename comment in the ASM when I start processing a file so that I know which VM file contained the crashing code.

To find the actual failing instruction, you may want to have your assembler generate a listing file that shows the ROM address for every instruction in the program.  See this post about my listing file.

For what it's worth, in my translation of Pong, 5497 is in Memory.alloc() in Memory.vm

 5488     4  @4
 5489  E308  M=D
                 // push that 0
                 // pop local 0
 5490     4  @THAT
 5491  FC30  AD=M
 5492  FC10  D=M
 5493     1  @LCL
 5494  FC20  A=M
 5495  E308  M=D
                 // goto WHILE_EXP0
 5496  5434  @Memory.alloc$WHILE_EXP0
 5497  EA87  0;JMP
                 // label WHILE_END0
 5498        (Memory.alloc$WHILE_END0)
                 // push local 0
 5498     1  @LCL
 5499  FC30  AD=M

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Debug pong

Gabrix

There is any way to execute and test single files?

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Debug pong

cadet1620
Administrator
Gabrix wrote
There is any way to execute and test single files?
There is no easy way to deal with testing individual files in a high-level application like Pong, especially in the case of the OS .vm files where you don't have the Jack source code.

You don't need to use your VM translator to complete chapters 9-12. All of the project tests expect that you are using the VMEmulator.

Once you have written your own Jack compiler and OS, it is quite a thrill to run your game in the CPU emulator, compiled with your compiler and translated along with your OS using your VM translator!

I recommend that you precede to chapter 9 and come back to debug your VM translator after chapter 12. You will have OS source available and you can have your compiler write the Jack source into the VM it generates, and those source comments will be carried through to the ASM listing file.  With my toolset, the listing file ends up looking like this, which is a great aid in debugging.
                 /// 125:     function void deAlloc(int object) {
                 /// 126:         var Array block;
                 /// 127:         var Array freeBlock;
                 /// 128:         var Array freePrev;
                 /// 129:
                 // function Memory.deAlloc 3
 3939        (Memory.deAlloc)
 3939     3  @3
 3940  ECD0  D=-A
 3941        ($148)
 3941     0  @SP
    ...
                 /// 130:         if (object = 0) {
                 // push argument 0
 3947     2  @ARG
 3948  FC30  AD=M
 3949  FC10  D=M

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Debug pong

Gabrix
Sorry but I can't attend because I have to send this project to my teacher, the debug print haven't any invalid code, can I send you my source? You can see the problem...
My Pong go in loop at the function Math.multiply 5, the loop is this:

<code>
label WHILE_EXP0
push local 2
push constant 1
sub
push argument 1
push constant 1
sub
lt
not
if-goto WHILE_END0
push local 3
push static 0
add
pop pointer 1
push that 0
push argument 1
and
push constant 0
eq
not
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push local 0
push argument 0
add
pop local 0
push local 2
push local 3
push static 0
add
pop pointer 1
push that 0
add
pop local 2
label IF_FALSE1
push argument 0
push argument 0
add
pop argument 0
push local 3
push constant 1
add
pop local 3
goto WHILE_EXP0
</code>
Loading...