8051 Addressing Modes

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

8051 Addressing modes

Addressing mode is a way to address an operand. Operand means the data we


are operating upon (in most cases source data). It can be a direct address of
memory, it can be register names, it can be any numerical data etc.

OR

An Addressing Mode is a way to locate a target Data, which is also called as


Operand. The 8051 Family of Microcontrollers allows five types of Addressing
Modes for addressing the Operands. They are

 Immediate Addressing
 Register Addressing
 Direct Addressing
 Register – Indirect Addressing
 Indexed Addressing

Immediate Addressing
 In Immediate Addressing mode, the operand, which follows the
Opcode, is a constant data of either 8 or 16 bits.
 The name Immediate Addressing came from the fact that the
constant data to be stored in the memory immediately follows the
Opcode.
 The constant value to be stored is specified in the instruction itself
rather than taking from a register.
 The destination register to which the constant data must be copied
should be the same size as the operand mentioned in the
instruction.
 Example: MOV A, #030H
 Here, the Accumulator is loaded with 30 (hexadecimal).
 The # in the operand indicates that it is a data and not the address
of a Register.
 Immediate Addressing is very fast as the data to be loaded is given
in the instruction itself.

Register addressing mode:


 In register addressing mode, the source and the destination both are
registers, and must be of same size as indifference is size will give errors.
 The data is specified in the registers for various operations as per the
given instructions.
 Only the Accumulator (A) and R0 to R7 registers of each memory bank
are allowed in this mode to transfer the data.
 The data transfer can take place between Rn(R0 to R7) registers and the
Accumulator (A) only and cannot be done between Rn registers.
 Ex: MOV A, R3; The contents of register R3 are copied to Accumulator
(A).
 ADD A, R4; the contents of register R4 are added with the contents of the
Accumulator (A) and the result is stored in the Accumulator (A).
 MOV DPTR, A; This instruction will end up giving error as there is size
indifference i.e. DPTR = 16 bits and A= 8 bits.

Direct Addressing Mode


 In this addressing mode, source and destination could be a register or a
RAM location, but both cannot be the same; either the source has to be a
register followed by RAM location as destination and vice versa.
 The address of the operand is specified in the instruction itself.
 Internal RAM addresses starting from location 00H to 7FH and SFR
addresses starting from 80H to FFH are only allowed in direct addressing
mode.
 Ex: MOV R3, 70H; The contents of RAM location 70H are copied to the
register R3. MOV 32H, A;
 The contents of Accumulator (A) are copied to RAM location 32H.

Register-Indirect addressing mode:


In this mode, the address of the operand is specified in a register. Only the
registers R0 and R1 are data pointers i.e. the data is stored on the RAM location
whose address is held by either R0 or R1.
It can only use addresses from 00H to 7FH.
@ sign is used in the instruction and is placed before the registers R0 and R1 to
make the two registers as pointers.
Ex: MOV A, @R0; The contents of the memory location held by [R0] is copied
to Accumulator (A).
MOV @R0, A ; The contents of Accumulator (A) are copied to the memory
location held by [R0].
MOV X A, @DPTR ; The contents of the external RAM location held by
[DPTR] (16-bit) are copied to the Accumulator (A).
MOV X A, @R0 ; The contents of external RAM location held by register [R0]
(8-bit) are copied to the Accumulator (A).

Indexed Addressing

 In this addressing mode, address is indirectly specified in Accumulator


(A), data pointer (DPTR) and program counter.
 It is usually the sum of the addresses stored at [A+DPTR] or [A+PC].
 This addressing mode is very useful because ROM contains permanent
data which is stored in the form of Look-Up tables.
 To access the Look-Up, the addresses are given as SUM of contents of
two registers, where one acts as the base and other acts as the index
within the table.
 Also this mode is used to access data from the code memory and is
denoted by "C" in the instruction.
 Ex: MOVC A, @A+DPTR; Contents of the ROM location pointed by the
sum of addresses A and DPTR (16-bits) are copied to Accumulator A.
 In this case the data pointer holds the base address and the accumulator
(8-bits) holds the index or displacement.

You might also like