Addressing Modes

The CPU can access data various ways The data could be in a register, or memory or as an immediate value
The various ways of accessing data are called addressing modes.  

Types of addressing mode

  1. Direct addressing mode
  2. Indirect addressing mode
  3. Register addressing
  4. Register specific addressing (optional)
  5. Immediate addressing
  6. External Addressing ( Index )       
    • Code access
    • Data access 

Direct addressing mode

  • In this mode the operand is specified by an  8-bit address field In the instruction.
  • One can access all the 128 bytes of internal RAM locations and each SFR.
  • If the MSB bit = 0 then the location is within on chip internal RAM. If MSB bit = 1 then the location is SFR.
  • The location 00h to 7Fh to address the internal RAM .
  • SFR addresses from 80h to FF H
SyntaxMnemonicsDestination OperandSource OperandComment
 MOVA,40H;Load the contents of RAM location 40H into A

Example:-

  • MOV R1, 45H   ;Move the contents of RAM location 45 into R1 register
  • MOV 47H,A       ;Move the contents of the accumulator into the RAM location 47h.
  • ADD A, 43H     ;Add the contents of the RAM location 43H to the accumulator           

Indirect Addressing Mode

In this addressing mode, the instruction specifics a register which contains address of an operand i.e. the register hold the actual address that will be used in the data move operation.

  • The R0 and R1 of each bank can be used as an index or pointer to memory location
  • The sign @ indicates the register acts as a pointer to memory locations
SyntaxMnemonicsDestination OperandSource OperandComment
 MOVA,@Ri;Load the contents of Memory location pointed by Ri register into A

Example:-

  • MOV A,@ R0 :Move the contents of  RAM location whose address is pointed to by R0 into A (accumulator)
  • MOV @ R1 , B : Move the contents of B into RAM location whose address is pointed to by R1

Example:- MOV A,@ R0
Note : only register R0 and R1 can be used for indirect addressing mode .
MOV A,@R2   invalid instruction. 

Register Addressing

  • Each bank consist of register R0 to R7 can be used as general purpose register for selection of bank register, the user has to modify the two bits of PSW
  • These register can be used to stored the address or data in the register addressing mode
SyntaxMnemonicsDestination OperandSource OperandComment
 MOVA,R7;Load the contents of R7 register into A

Example:-

  • MOV A,R0   ;Move or load the contents of the register R0 to the accumulator
  • ADD A,R6     ;Add the contents of R6 register to the accumulator
  • MOV P1, R2  ;Move the contents of the R2 register into port 1
  • MOV R5, R2   ;This is invalid .The data transfer between the registers is not allowed.

Note: MOV R3,R5 is an invalid instruction

Register specific Addressing Mode

In this addressing mode the instruction refer to a specific registers such as accumulator or data pointer 

Example :-

  • DA A  ; Decimal adjust accumulator
  • SWAP A  ; Swap lower nibble with Higher nibble

Immediate Addressing Mode

  • This method is the simplest method to get the data. 
  • In this addressing mode the source operand is a constant rather then a variable.
  • As the data source is a part of instruction 
  • The # sign indicates that the data followed is immediate operand. 
SyntaxMnemonicsDestination OperandSource OperandComment
 MOVA,#30H;Load the immediate value 30H into A

Example:-MOV A,#30h
              MOV P1,#0FF
              MOV DPTR, #1234h

External addressing modeor Indexed addressing mode

Code access (ROM access)

  • Using these instructions only program memory can be accessed.
  • This addressing mode is preferred for reading look up tables in the program memory.
  • Either DPTR or PC can be used as pointer. 
SyntaxMnemonicsDestination OperandSource OperandComment
 MOVCA,@A+DPTR;Load the immediate value present at memory location pointed to by @A+DPTR in A

Example:-

  • MOVC A,@A+DPTR ;Load the immediate value present at memory location pointed to by @A+DPTR in A
  • MOVC A,@A+PC      ;Load the immediate value present at memory location pointed to by @A+PC in A

Data access (RAM access)

  • Using this addressing mode the programmer can access the external Data memory 
SyntaxMnemonicsDestination OperandSource OperandComment
 MOVXA,@A+DPTR;Load the immediate value present at memory location pointed to by @A+DPTR in A

Example:-  

  • MOVX A,@DPTR ;Load the immediate value present at memory location pointed to by @DPTR in A
  • MOVX @R0,A        ;Load the immediate value present in A into memory location pointed to by @R0

References

  • WikiNote Foundation
Tags:
Created by Sujit Wagh on 2017/08/19 17:03