Comparison failure at line 2

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

Comparison failure at line 2

jfmolderez
This post was updated on .
I cannot figure out what could go wrong with the comparison in the following lines of Jack code :

var int i;
let i = 0;

while (i < 16) {
    ....
    let i = i + 1;
}

However I get "Comparison failure at line 2" ???????

Screenshot - VMEmulator
Reply | Threaded
Open this post in threaded view
|

Re: Comparison failure at line 2

WBahn
Administrator
You've given virtually nothing to go on.

What did YOUR output produce?

Where did it fail to match the comparison file?

You have 14 tests, which ones did it pass and which ones did it fail?

We are NOT mind readers!
Reply | Threaded
Open this post in threaded view
|

Re: Comparison failure at line 2

jfmolderez
I have only tested the first module: Math.

This is the MathTest.out :
|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]|RAM[8006]|RAM[8007]|RAM[8008]|RAM[8009]|RAM[8010]|RAM[8011]|RAM[8012]|RAM[8013]|
|       6 |    -180 |  -18000 |  -18000 |       0 |       3 |   -3000 |       0 |       3 |       0 |       0 |       0 |       0 |       0 |

and this is MathTest.cmp :
|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]|RAM[8006]|RAM[8007]|RAM[8008]|RAM[8009]|RAM[8010]|RAM[8011]|RAM[8012]|RAM[8013]|
|       6 |    -180 |  -18000 |  -18000 |       0 |       3 |   -3000 |       0 |       3 |     181 |     123 |     123 |      27 |   32767 |
Reply | Threaded
Open this post in threaded view
|

Re: Comparison failure at line 2

WBahn
Administrator
So you can see that your code is putting zero in locations 8009 through 8013 (i.e., r[9] through r[13]).

Looking at the Main.jack code, we can see that these lines are:

        let r[9] = Math.sqrt(32767);       // 181
       
        let r[10] = Math.min(345, 123);    // 123
        let r[11] = Math.max(123, -345);   // 123
        let r[12] = Math.abs(27);          // 27
        let r[13] = Math.abs(-32767);      // 32767
 
It's a bit interesting that it's the last five that are wrong, especially since you got r[8], Math.sqrt(9), correct.

I'd recommending first just moving the last five lines up in the .jack file to just after where r is set to 8000 and see if you get the same results.

Reply | Threaded
Open this post in threaded view
|

Re: Comparison failure at line 2

jfmolderez
Ok : solved .Thanks for the help  
I had indeed to be more careful about the edge case sqrt(32767).