Symbols and labels

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

Symbols and labels

Slight_Of_Nand
Quick question:

When a symbol is used as a label to point to a line of code does it simply point to the memory location for the instruction directly below it?  Or, does is it interpreted by the assembler to go to the line number of that program?
Reply | Threaded
Open this post in threaded view
|

Re: Symbols and labels

Slight_Of_Nand
I think I've just solved my own problem:

Memory allocation for the program starts at line 0 therefore if LOOP is line 2 then got LOOP would goto Memory Address [2] which is also line 2 of the program.

So infact my question from above has the answer - it does both.

Am I correct?
Reply | Threaded
Open this post in threaded view
|

Re: Symbols and labels

WBahn
Administrator
Slight_Of_Nand wrote
I think I've just solved my own problem:

Memory allocation for the program starts at line 0 therefore if LOOP is line 2 then got LOOP would goto Memory Address [2] which is also line 2 of the program.

So infact my question from above has the answer - it does both.

Am I correct?
It's hard for me to tell because I'm having a hard time figuring out exactly what you are saying.

Each instruction in your assembly language program will be translated into one line in the machine code program file. Those lines will be loaded into ROM starting with address 0. A label in your assembly language program need to be associated with the ROM address of the next instruction.

You can't use the line number in the assembly language program where the label appears to determine which number associate with that label because there can be an arbitrary number of lines in the file before the label that did not produce a machine code instruction. Examples include comment lines, blank lines, or other labels.

You simply need to keep track of how many machine code instructions you have already written to the .hack file. When you encounter a new label, that is the number that needs to be associated with that label because that is the address that the next instruction will end up being stored at in ROM.