Basic Loop Comparison Failure

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

Basic Loop Comparison Failure

lnorman917
I am getting a "Comparison failure at line 2" when running BasicLoop.tst

My out is:
| RAM[0] |RAM[256]|
|    321 |     53 |

which is obviously different than the cmp:
| RAM[0] |RAM[256]|
|    257 |      6 |


I went over my code and I can't see where this is failing. How do I go about fixing this?
Reply | Threaded
Open this post in threaded view
|

Re: Basic Loop Comparison Failure

cadet1620
Administrator
First think that you want to do if you havent already done so is write the VM source as comments in your ASM output. This will let you have the ASM file open in a text editor at the same that you are stepping in the CPUEmulator and will save you from getting lost in the ASM code.
    A=M
    M=D
// label LOOP_START
(BasicLoop$$LOOP_START)
// pop argument 0      // counter--
    @SP
    ...
    M=D
// push argument 0
    @ARG
    ...
    M=D
// if-goto LOOP_START  // If counter != 0, goto LOOP_START
    @SP
RAM[0] is the stack pointer.  The test initializes it to 256 and at the end of the test everything that was pushed onto the stack should have been popped or consumed by an operator like 'add'. As the final command, the sum is pushed onto the stack so the final SP value should be 257.

Your test is ending with a large value in SP so it looks like you have an operator that is not properly consuming its operands.  The new operator in this test is 'if-goto' so look closely at its generated ASM and step through it to see that it's doing what you think it is. You might want to step through BasicLoop.vm using BasicLoopVME.tst to confirm that you understand how "if-goto" is supposed to work.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Basic Loop Comparison Failure

lnorman917
Ahhhh... ok I went and inserted comments which helped me realize that when adapting my project 7 Codewriter to project 8 I messed up my writepushpop. Silly mistake.

I have everything working now except NestedCall. It seems my out is just a little bit off:

cmp:
| RAM[0] | RAM[1] | RAM[2] | RAM[3] | RAM[4] | RAM[5] | RAM[6] |
|    261 |         261 |      256 |    4000 |     5000 |      135 |      246 |

out:
| RAM[0] | RAM[1] | RAM[2] | RAM[3] | RAM[4] | RAM[5] | RAM[6] |
|    261 |         261 |      256 |     4000 |    5000 |      240 |         -1 |

Given that RAM[5] and RAM[6] are off, does this indicate something wrong with my temp?
Reply | Threaded
Open this post in threaded view
|

Re: Basic Loop Comparison Failure

cadet1620
Administrator
It's a good bet that something's wrong with 'push temp'.  The -1 in RAM[6] was initialized by the test script before the ASM code ran.

If you can't find your problem, feel free to send me your ASM output and I'll take a look at it when I get the chance.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Basic Loop Comparison Failure

lnorman917
It was in fact something wrong with my temp. Thanks!