Chap#5. Addressing Modes
Chap#5. Addressing Modes
48
Addressing Modes
(04 hours)
49
MOV R2, R5 : Wrong due to rule. You must not need this instruction
Note: If the instruction just contains A (Accumulator) register, we will not consider the
instruction in Register addressing mode. Also it is important that in 8051 we have 8 registers except A & B
registers. While in PIC Micro-Controller Accumulator is known as Work Register and whole RAM and
Ports are known as File Register
50
TIP: (The obvious question that may arise is, "If direct addressing an address from 80h through
FFh refers to SFRs, how can I access the upper 128 bytes of Internal RAM that are available on the 8052?"
The answer is: You can’t access them using direct addressing. As stated, if you directly refer to an address
of 80h through FFh you will be referring to an SFR. However, you may access the 8052s upper 128 bytes
of RAM by using the next addressing mode, "indirect addressing.”)
51
As you can see, both commands utilize DPTR. In these instructions, DPTR must first be
loaded with the address of external memory that you wish to read or write. Once DPTR holds the
correct external memory address, the first command will move the contents of that external
memory address into the Accumulator. The second command will do the opposite: it will allow
you to write the value of the Accumulator to the external memory address pointed to by DPTR.
52
5.1.8 Absolute Addressing
This type of addressing is specific to 8051 Micro-Controller. Absolute addressing is used
only with the ACALL and AJMP instructions. These two byte instructions allow branching
within the current 2K page of code memory by providing the 11 least-significant bits of the
destination address in the op-code. 3 bits in first byte (A10-A8) and 8 bits in 2nd Byte of the instruction
(A7-A0), Upper 5 bits in first Byte determines the 2K page. Thus the Upper 5 bits of program counter
does not change in response of this instruction, while lower 11 bits are changed with given 11 bits
from instruction as shown here.
11100001 => 1st Byte (A10-A8 + op-code)
nd
01000110 => 2 Byte (A7-A0)
So the lower 11 bits will be 11101000110. The upper 5 bits of program counter will not
change (remain same as previous) while lower 11 bits will be replaced by given 11 bits. Thus the
new value of program counter will be XXXXX11101000110 here XXXXX represents previous
address that is not updated in execution of instruction.
Remember that the main difference between Relative Addressing and Absolute Addressing is that
Relative Addressing has offset address that is added in current address of program counter, while in
Absolute Addressing the Program counter is updated with the 11bits given in the 2 Byte instructions.
53
5.2 Application of Addressing mode in programming
To understand the advantages and applications of addressing modes in Micro-Controller
or Micro-Processor we need the clear view regarding different Addressing Modes. Also different
systems support different types of addressing modes. So if we prepare software for one type of
Micro-Controller, it may not work on other Micro-Controller.
The specific of each type of addressing modes are important for computer programmers
using assembly language, as assembly language is direct representation of the machine
instructions sent to the CPU. This is what makes assembly language much faster than all other
languages.
Addressing modes enables the programmer to make the software more efficient i.e. a
software developer may not use Long Addressing where he can use Absolute or Relative
addressing. Also by the understanding of addressing modes we get the limitation of commands.
For example CJNE, DJNZ, JNB, JNC, JB and JC commands have limitation of jump within ±127
offset of code space. So the programmer without knowledge about this limitation will not be able
to resolve the errors due to this limitation.
Conclusion of our discussion is that Addressing modes are much important in
programming, however it is affected in Assembly Language programming only. In higher level
languages the compiler is made enough efficient to manipulate the Addressing modes and
programmer has no concern with Addressing issues.
54