0% found this document useful (0 votes)
226 views3 pages

Addressing Modes in 8051 Microcontroller

Uploaded by

dancangichobi762
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
226 views3 pages

Addressing Modes in 8051 Microcontroller

Uploaded by

dancangichobi762
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Addressing Modes

An "addressing mode" refers to how you are addressing a given memory location. In
summary, the addressing modes are as follows, with an example of each:

Immediate Addressing Mode


Register Addressing Mode
Direct Addressing Mode
Register Indirect Addressing Mode
Indexed Addressing Mode

Each of these addressing modes provides important flexibility.

Immediate Addressing

In this addressing mode, the source operand is a constant. In immediate addressing mode,
the operand comes immediately after the opcode. Notice that the immediate data must be
preceded by the pound sign “#”.

MOV A,#25H ; load 25H into A

MOV R3, # 67H ; load 67H into R4 register.

MOV DPTR, #9250H ; load 9250H into DPTR(Data Pointer)

Immediate addressing is very fast since the value to be loaded is included in the
instruction.

However, since the value to be loaded is fixed at compile-time it is not very flexible.

Register Addressing

Register addressing mode involves the use of registers to hold the data to be manipulated.
Examples of register addressing mode follow;

MOV A, R0 ; copy the contents of R0 into A

MOV R5, A ; copy the contents of A into R5

It should be noted that the source and destination registers must match in size.

Ex: MOV DPTR, A ; is invalid

[Link] Asst. Prof. in Electronics, St. Joseph’s Degree & PG College, Page 1
Autonomous-Affiliated to Osmania University, Accredited by NAAC with Grade ‘A’
Notice that we can move data between the accumulator and Rn ( for n=0 to 7) but transfer
of data between Rn registers is not allowed. For example the following instruction is
invalid

MOV R2, R6;

Direct Addressing
In Direct addressing mode the value to be stored in memory is obtained by directly
retrieving it from another memory location. For example:

MOV A,30h

This instruction will read the data out of Internal RAM address 30 (hexadecimal) and
store it in the Accumulator.

Direct addressing is generally fast since, although the value to be loaded is not included
in the instruction, it is quickly accessible since it is stored in the 8051s Internal RAM. It
is also much more flexible than Immediate Addressing since the value to be loaded is
whatever is found at the given address--which may be variable.

Also, it is important to note that when using direct addressing any instruction which
refers to an address between 00h and 7Fh is referring to Internal Memory.

Stack and Direct Addressing mode

Another major use of direct addressing mode is the stack. In the 8051 only direct
addressing mode is allowed for pushing onto the stack. Therefore, an instruction such as
PUSH A is invalid. Pushing the accumulator contents onto the stack mush be coded as
“PUSH 0E0H”, where 0E0 is the address of register A. Direct addressing mode must be
used for the POP instruction as well.

Register Indirect Addressing


Indirect addressing is a very powerful addressing mode. In the register indirect
addressing mode, a register is used as a pointer to the data. If the data is inside the CPU,
only registers R0 and R1 are used for this purpose. In other words, R2-R7 cannot be used
to hold the address of an operand located in RAM when using this addressing mode.
When R0 and R1 are used as pointers, that is when they hold the address of RAM
locations, they must be preceded by the “@” sign.

MOV A, @R0 ; move contents of RAM location whose address is held by R0 into A

[Link] Asst. Prof. in Electronics, St. Joseph’s Degree & PG College, Page 2
Autonomous-Affiliated to Osmania University, Accredited by NAAC with Grade ‘A’
MOV @R1, B ; move contents of B into RAM location whose address is held by R1

For example, lets say R0 holds the value 40h and Internal RAM address 40h holds the
value 67h. When the above instruction is executed the 8051 will check the value of R0.
Since R0 holds 40h the 8051 will get the value out of Internal RAM address 40h (which
holds 67h) and store it in the Accumulator. Thus, the Accumulator ends up holding 67h.

Indirect addressing always refers to Internal RAM; it never refers to an SFR

Limitations of Register Indirect Addressing mode

As stated above, R0 and R1 are the only registers that can be used for pointers in register
indirect addressing mode. Since R0 and R1 are 8 bits wide, their use is limited to
accessing any information in the internal RAM(scratch pad memory of 30H to 7FH ).
However, there are times when we need to access data stored in external RAM or in the
code space of on-chip ROM. Whether accessing externally connected RAM or on-chip
ROM, we need a 16-bit pointer. In such cases, the DPTR register is used.

Indexed Addressing Mode

Indexed addressing mode is widely used in accessing data elements of look-up table
entries located in the program ROM space of the 8051 microcontroller. The instruction
used for this purpose is “MOVC A, @A + DPTR”. The 16-bit register DPTR and register
A are used to from the address fo the data element stored in on-chip ROM. Because the
data elements are stored in the program (code) space ROM of the 8051, the instruction
MOVC is used instead of MOV. The “C” means code in this instruction the contents of A
are added to the 16- register DPTR to form the 16-bit address of the needed data.

[Link] Asst. Prof. in Electronics, St. Joseph’s Degree & PG College, Page 3
Autonomous-Affiliated to Osmania University, Accredited by NAAC with Grade ‘A’

Common questions

Powered by AI

In the 8051 microcontroller, direct addressing mode is used for operations involving the stack. When data is pushed onto the stack, the direct addressing mode specifies the memory address from where data should be obtained. An example is using the instruction “PUSH 0E0H” to push the accumulator contents onto the stack, where 0E0H is the direct address of the accumulator. This use of direct addresses ensures that stack operations are precise and handle the correct data from the registers referenced by their memory addresses. Direct addressing remains the only allowed mode for both PUSH and POP stack operations .

Direct addressing mode and register indirect addressing mode in the 8051 microcontrollers differ primarily in their flexibility and method of accessing data. In direct addressing, the address of the operand is explicitly specified, allowing fast access to known memory locations, such as when loading data from specific addresses within the internal RAM, but it lacks flexibility for changes during runtime . Conversely, register indirect addressing mode uses registers R0 or R1 to dynamically point to operand addresses in internal RAM, thus offering more flexibility for operations that require dynamic data handling, like traversing through arrays or iterating over lists (e.g., using R0 to point to changing buffer locations). This mode, however, is limited by only utilizing R0 and R1, restricting wider addressability without using DPTR for external memory accesses.

The indexed addressing mode in the 8051 microcontroller is particularly useful when accessing data elements of look-up tables stored in the program ROM space. This mode is preferable in scenarios where you need to retrieve data from fixed locations in the ROM that are offset from a base address stored in a register (such as DPTR), which effectively leverages the computation of the final address by adding the contents of A to DPTR. This operation is efficient in accessing elements stored in contiguous locations, such as in tables used for functions like character encoding or control algorithms .

Register indirect addressing mode is considered more powerful than direct addressing mode because it allows for dynamic addressing where the operand address can be changed during execution. This capability enables flexible data manipulation at runtime by using registers like R0 or R1 to point to memory locations, thereby allowing operations like iterating over arrays or managing dynamically changing data structures. Although it has limitations, such as the restriction to using only R0 and R1 for internal RAM and not being able to access memory beyond 7FH without DPTR, the flexibility of runtime address modification makes it invaluable for complex data handling scenarios .

Constraints in the register addressing mode of the 8051 microcontroller include the requirement that the source and destination registers must match in size. This restriction is significant in programming because it prevents the movement of data between registers that vary in size, which could otherwise lead to unpredictable results or errors. For example, transferring the contents of a general-purpose register to the DPTR is invalid because the DPTR is a 16-bit register while other registers like R0-R7 and A are 8-bit. Such constraints dictate how data is managed within the processor's internal environment, influencing how programmers can optimize register utilization and performance efficiency .

The pound sign "#" is significant in the immediate addressing mode instruction set of the 8051 microcontroller because it denotes that the operand following the sign is a literal constant value to be used directly in the operation rather than an address of a memory location. This distinction is vital because it informs the assembler how to interpret the operand. For example, in the instruction "MOV A,#25H", the "#" indicates that the hexadecimal number 25 is the immediate value to be loaded into the accumulator A, not a memory address from which the value should be retrieved .

The instruction "MOV R2, R6" is considered invalid in the register addressing mode of the 8051 microcontroller due to the limitation that prohibits direct data transfer between register pairs. Such an invalid instruction would typically be flagged by the assembler during the compilation process, producing an error message to indicate non-compliance with the microcontroller's instruction set constraints. This early detection by the assembler helps to prevent potential runtime errors, ensuring that only valid instructions meeting the architecture's operational requirements are executed on the microcontroller .

Challenges in using only R0 and R1 for register indirect addressing in 8051 microcontrollers include a limited ability to manage more extensive data structures or perform multiple simultaneous pointer operations requiring distinct registers. This limitation is significant when programming sophisticated applications needing to manipulate complex data within internal RAM. Mitigation strategies involve using the DPTR for addressing memory beyond immediate internal RAM or structuring code with consideration of the limited register availability to dynamically switch pointers as needed. Additionally, efficient code optimization practices, such as minimizing register use where possible, can alleviate constraints imposed by using only two pointer-capable registers .

The DPTR (Data Pointer) register, which is a 16-bit register, plays a crucial role in the indirect addressing mode when accessing external RAM or ROM in the 8051 microcontrollers because it provides the necessary wider address range needed to point to locations beyond the internal RAM. When only internal RAM is accessed, which is limited to addresses between 30H to 7FH, R0 and R1 registers, being 8-bits wide, are sufficient to serve as pointers in the register indirect addressing mode. However, when addressing memory outside this space, such as external RAM or on-chip ROM, the 8-bit width of R0 and R1 becomes a limitation, and a 16-bit pointer like DPTR is required .

Immediate addressing mode in the 8051 microcontroller improves execution speed because the operand is defined as a constant and is embedded directly within the instruction itself. This means the data does not need to be fetched from a separate memory location, which speeds up instruction execution . However, this also results in a limitation in flexibility since the operand value is fixed during compile time, making it unsuitable for cases where operand values need to dynamically change during execution .

You might also like