Little Man Computer - Labels

Labels

Without labels the programmer is required to manually keep track of mailbox (memory) locations. In the numeric example, if a new instruction was to be inserted before the final HLT instruction then that HLT instruction would move from address 07 to address 08 (address labeling starts at address location 00). Suppose the user entered 600 as the first input. The instruction 308 would mean that this value would be stored at address location 08 and overwrite the 000 (HLT) instruction. Since 600 means "branch to mailbox address 00" the program, instead of halting, would get stuck in an endless loop.

To work around this difficulty, most assembly languages (including the LMC) allow the use of labels. A label is simply a word that is used to either name a memory address where an instruction or data is stored, or to refer to that address in an instruction.

When a program is assembled.

  • A label to the left of an instruction mnemonic is converted to the memory address the instruction or data is stored at.
  • A label to the right of an instruction mnemonic takes on the value of the memory address referred to above.

In the assembly language example which uses mnemonics and labels, if a new instruction was inserted before the final HLT instruction then the address location labeled FIRST would now be at memory location 09 rather than 08 and the STA FIRST instruction would be converted to 309 (STA 09) rather than 308 (STA 08) when the program was assembled.

Labels are therefore used to:

  • identify a particular instruction as a target for a BRANCH instruction
  • identify a memory location as a named variable (using DAT) and optionally load data into the program at assembly time for use by the program (this use is not obvious until one considers that there is no way of adding 1 to a counter. One could ask the user to input 1 at the beginning, but it would be better to have this loaded at the time of assembly)

Read more about this topic:  Little Man Computer

Famous quotes containing the word labels:

    The Prime Minister has an absolute genius for putting flamboyant labels on empty luggage.
    Aneurin Bevan (1897–1960)

    In the range of things toddlers have to learn and endlessly review—why you can’t put bottles with certain labels in your mouth, why you have to sit on the potty, why you can’t take whatever you want in the store, why you don’t hit your friends—by the time we got to why you can’t drop your peas, well, I was dropping a few myself.
    Mary Kay Blakely (20th century)