Having trouble in handling variable symbols

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

Having trouble in handling variable symbols

thedumbone
I have written code such that when a new variable symbol appears, it gets values from 16 onwards.

For example, @i would translate to 0000 0000 0001 0000 and @sum would translate to 17 (in binary) in the .hack file. But the file that the provided assembler generates outputs from 10 onwards, while incrementing twice. Example, @i would translate to 10 and @sum would translate to 12, then 14 etc.

What am I missing here?
Reply | Threaded
Open this post in threaded view
|

Re: Having trouble in handling variable symbols

ivant
Can you give a small but full example program in HACK assembly and what your assembler generates for it?
Reply | Threaded
Open this post in threaded view
|

Re: Having trouble in handling variable symbols

thedumbone


this is the comparison from Max.asm

Similarly, all symbol-less files are generating correct code but when I assemble the .asm files with symbols, my assembler generates different code. I think my code is correct since there are few mentions about some bug in the provided assembler. Could you check that? if my code is wrong or there's a bug?

function that translates A instructions: (for your reference)

Reply | Threaded
Open this post in threaded view
|

Re: Having trouble in handling variable symbols

ivant
The problem is, that OUTPUT_FIRST is actually defined in the source code as a label so you should not treat it as a variable.

How can you handle this case?
Reply | Threaded
Open this post in threaded view
|

Re: Having trouble in handling variable symbols

pm100
In reply to this post by thedumbone
OUTPUT_FIRST is a label, it is at offset 10 thats why the assembler inserts 10 there, same for OUTPUT_D

You need to distingush between @<label> @<number> and @<variable>

When you hit @xxx you need to check to see if there is a (xx) if so then insert the offset of xx, otherwise generate a new variable address starting at 16
Reply | Threaded
Open this post in threaded view
|

Re: Having trouble in handling variable symbols

thedumbone
In reply to this post by ivant
Thank you. it's working after fixing the code