5. Symbolic addressing

So far, we have discussed mnemonics, opcodes and operands. But another key aspect of programming is to fetch or store data and instructions from memory.

The simplest way to do this is to refer directly to a memory location such as #3001. But this brings a number of problems

  • it is difficult to see the meaning of the data in location #3001
  • the data may not be able to be located at #3001 because another program is already using that location.

To overcome this issue, the idea of 'symbolic addressing' is used. Instead of referring to an absolute location, the assembly language allows you to define a 'symbol' for the data item or location. Like this

  .MODEL SMALL Use small memory model
  .STACK 2048 define the stack
DIAM EQU 2 define a constant called diam
VarA DB define a variable called VarA as a byte
VarB DW define a variable called VarB as a word
main: MOV AL,[VarA] Move data in VarB into register AL

The symbols being defined by this bit of code are DIAM, VarA, VarB. In the case of DIAM it is referring to a constant value of 2. The size of the variables VarA and VarB are defined, but notice that their location is not defined.

It is the job of the assembler to resolve the variables into locations in memory.

The advantages of using symbolic addressing over direct memory references are:

  • The program is re-locatable in memory. It does not particularly care about its absolute location, it will still work
  • Using symbols makes the software much more understandable

When the code is ready to be loaded and run, a 'symbol table' is created by the assembler for the linker and loader to use to place the software into memory.


Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: symbolic addressing



Copyright © www.teach-ict.com