Hi,
I am writing code to compile main.jack of ConvertToBinary test program of Project 11.
Referring to Fig 11.6 on page 236 in book, in every new symbol table for subroutine, I add 'this' as first argument type entry like
name=this
Type=className
Kind=argument
index=0
This seems to be causing problem when compiling following function in main.jack
function void convert(int value) {
var int mask, position;
var boolean loop;
let loop = true;
while (loop) {
let position = position + 1;
let mask = Main.nextMask(mask);
if (~(position > 16)) {
if (~((value & mask) = 0)) { do Memory.poke(8000 + position, 1);
}
else {
do Memory.poke(8000 + position, 0);
}
}
else {
let loop = false;
}
}
return;
}
What seems to happening is that in the highlighted command below the argument variable when pushed on stack is being pushed as 'push argument 1' unlike the code generated by the supplied Jack Compiler, which prints this line as 'push argument 0'.
Outputs from my compiler and from supplied Jack Compiler are pasted below side-by-side.
The symbol tables when compiling the file are as below
There might be other problems with the code but this one seems looks so obvious.
Does it have something to do with the symbol tables or does it have to do with how I am writing code for if-else.
Thanks.