Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/03/11 07:56
Read: times


 
#181678 - the Assembler tells you.
Responding to: ???'s previous message
Absolute addressing means that you specify the destination and it remains fixed. e.g. goto 1234
Relative addressing means that that it is relative to the original instruction. e.g. goto PC+56.

If the PC was 1178, then the destination address is still 1234.

You may have noticed that most branches are fairly short. Some subroutines may not be very far away. So if you can encode the operand in one byte rather than two, it uses less program memory. Relative addressing for the 8051 uses -127 to +128 and hence fits in one byte.

You may have also noticed that "LCALL 1234" will always execute the subroutine at 1234. If all the opcodes were moved by one byte, the opcodes and operands would have to be re-calculated to account for the changes in PC.

With Relative addressing, you could store your program anywhere in memory and never have to re-calculate. This is never really used with an 8051.

An assembler lets you specify expressions in different ways. You commonly just use the label directly. The assembler then uses whichever opcode is both legal and matches your instruction.

It will tell you if your instruction is the wrong syntax (no opcode matches) or if it cannot evaluate the operand. e.g. the opcode needs the operand to fit in 'PC-127' to 'PC+128' range.

These errors can occur with JC type opcodes or even with AJMP type opcode. (AJMP needs to refer to destinations in the same 'page')

Read your assembler manual, and the opcode descriptions.

David.


List of 21 messages in thread
TopicAuthorDate
problem with simulator?            01/01/70 00:00      
   First of all            01/01/70 00:00      
      normally?            01/01/70 00:00      
         RE: "normally"            01/01/70 00:00      
   just saw it            01/01/70 00:00      
      Erik            01/01/70 00:00      
         "bible time"            01/01/70 00:00      
   Thanks but....            01/01/70 00:00      
      all the same            01/01/70 00:00      
      Learning requires study            01/01/70 00:00      
         a small correction            01/01/70 00:00      
         Thankyou            01/01/70 00:00      
            the chips listed ....            01/01/70 00:00      
   bit/byte addressing            01/01/70 00:00      
   "unknown label"            01/01/70 00:00      
      Use code tags            01/01/70 00:00      
         relative addressing            01/01/70 00:00      
            the Assembler tells you.            01/01/70 00:00      
            How would I find out if the labels are undefined?            01/01/70 00:00      
         nope            01/01/70 00:00      
         horribly wrong            01/01/70 00:00      

Back to Subject List