written 6.1 years ago by | • modified 6.1 years ago |
Addressing modes is an approach in which operands are given in an instruction for further operation in an assembly language code of most of the CPU with an instruction set. 8051 supports 5 addressing modes, which are explained as follows;
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 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.
Immediate addressing mode: In this addressing mode, the data is directly specified in the instruction itself. The source is the immediate data and the destination of this instruction could be any register. "#" symbol specifies that the operand is an immediate data on which operation is to be performed and the result will be stored in the destination register.
Ex: MOV A, #65H ; The digit 65H is copied to the Accumulator (A). MOV DPTR, #1615H ; A 16 bit digit 1615H is copied to Data pointer which is 16 bits.
Indirect addressing mode: In this mode, the address of the operand is specified in the 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 mode: 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.
written 6.1 years ago by |
- Indexed addressing mode: 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 are copied to Accumulator A.