24
8051 Addressing Modes 8051 Addressing Modes Upon completion of this chapter, you will Upon completion of this chapter, you will be able to be able to List the five addressing modes of the List the five addressing modes of the 8051. 8051. Compare and contrast the addressing modes. Compare and contrast the addressing modes. Code 8051 Assembly language instructions Code 8051 Assembly language instructions using each addressing mode. using each addressing mode. Access RAM using various addressing modes. Access RAM using various addressing modes. List the SFR addresses. List the SFR addresses.

8051 Addressing Modes

Embed Size (px)

DESCRIPTION

8051 Addressing Modes

Citation preview

  • 8051 Addressing Modes

    Upon completion of this chapter, you will be able to

    List the five addressing modes of the 8051.Compare and contrast the addressing modes.Code 8051 Assembly language instructions using each addressing mode.Access RAM using various addressing modes.List the SFR addresses.
  • 8051 Addressing Modes

    What is meant by addressing modes?

    Various ways of accessing data which could be in a register, or in memory, or be provided as an immediate value.

    The various addressing modes of a microprocessor are determined when it is designed and therefore cannot be changed by the programmer.

  • 8051 Addressing Modes

    Five distinct addressing modes:

    ImmediateRegisterDirectRegister IndirectIndexed
  • 8051 Addressing Modes

    Immediate Addressing Mode:

    The source operand is a constant.When the instruction is assembled, the operand comes immediately after the opcode.The immediate date must be preceded by the pound sign, #.Can be used to load information into any register, including the DPTR register.
  • 8051 Addressing Modes

    Immediate Addressing Mode:

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

    MOV R4, #62;load decimal value 62 into R4

    MOV B, #40H;load 40H into B

    MOV DPTR, #4512H;DPTR = 4512H

  • 8051 Addressing Modes

    Immediate Addressing Mode:

    Although the DPTR register is 16-bit, it can also be accessed as two 8-bit registers, DPH and DPL.

    MOV DPTR, #4532H;DPTR = 4512H is the same as

    MOV DPL, #32H

    MOV DPH, #45H

  • 8051 Addressing Modes

    Immediate Addressing Mode:

    COUNT EQU 30

    MOV R4, #COUNT ;R4=1E (30=1EH)

    MOV DPTR, #MYDATA;DPTR=200H

    ORG 200H

    MYDATA: DB America

  • 8051 Addressing Modes

    Register Addressing Mode:

    Involves the use of registers to hold the data to be manipulated.

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

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

    ADD A, R5;add the contents of R5 to A

    ADD A, R7;add the contents of R7 to A

    MOV R6, A;save accumulator in R6

  • 8051 Addressing Modes

    Register Addressing Mode:

    Source and destination registers must match in size.

    Example:

    MOV DPTR, A is invalid because the source is a 8-bit register and the destination is a 16-bit register.

  • 8051 Addressing Modes

    Register Addressing Mode:

    Movement of data between accumulator and Rn (n=0 to 7) is possible. Movement of data between Rn registers is not allowed.

    Example:

    MOV R4, R7 is invalid.

    Also, MOV DPTR, #25F5H can be written as

    MOV R7, DPL

    MOV R6, DPH

  • Review Questions

    Can the programmer of a microcontroller make up new addressing modes?Show the instruction to load 1000 0000 (binary) into R3. Why is the following invalid? MOV R2, DPTRDPTR is a 16-bit register that is also accessible in low-byte and high-byte formats. True or false?Is the PC (Program Counter) also available in low-byte and high-byte format?
  • 8051 Addressing Modes

    Direct Addressing Mode

    The data is in a RAM location whose address is known, and this address is given as a part of the instruction. The # sign distinguishes between direct and immediate addressing mode.

    RAM locations:

    00-1FH: register banks and stack

    20-2FH: bit addressable space to save single bit data

    30-7FH: place to save byte-sized data

  • RAM memory space allocation in the 8051

    7FH

    30H

    2FH

    20H

    1FH

    17H

    10H

    0FH

    07H

    08H

    18H

    00H

    Register Bank 0

    (Stack) Register Bank 1

    Register Bank 2

    Register Bank 3

    Bit-Addressable RAM

    Scratch pad RAM

  • 8051 Addressing Modes

    Direct Addressing Mode

    MOV R0, 40H; move content of RAM location 40H in R0

    MOV 56H, A ; move content of A to 56H

    MOV R4, 7FH; move content of 7FH to R4

  • 8051 Addressing Modes

    Direct Addressing Mode

    RAM locations 0 to 7 are allocated to bank 0 registers R0-R7. These registers can be accessed in two ways.

    MOV A, 4; is same as

    MOV A,R4; which means copy R4 into A

    MOV A,2; is same as

    MOV A, R2; which means copy R2 into A

  • 8051 Addressing Modes

    Direct Addressing Mode

    Although it is easier to use the names R0-R7 than their memory addresses, RAM locations 30H to 7FH cannot be accessed in any way other than their addresses since thy have no names.

  • SFR and their addresses

    SFR like A, B, PSW and DPTR have addresses too.Can be accessed by their names or by their addresses.Example:

    MOV 0E0H, #55H ; is the same as

    MOV A, #55H ; which means load 55H into A

    MOV 0E0H, R2 ; is the same as

    MOV A, R2 ; which means copy R2 into A

  • SFR and their addresses

    Have addresses between 80H and FFH, since the addresses 00 to 7FH are addresses of RAM memory inside the 8051.Not all the address space is used by SPR. The unused locations are reserved and must not be used by the 8051 programmer.

    Note:

    Address value is limited to one byte, 00-FFH in direct addressing mode.
  • 8051 Addressing Modes

    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.R2-R7 cannot be used to hold the address of an operand located in RAM when using this mode.When using R0 and R1 as pointers, they must be preceded by the @ sign.
  • 8051 Addressing Modes

    Register Indirect Addressing Mode

    Example:

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

    MOV @R1, B; move contents of B into RAM location whose address is held by R1

  • 8051 Addressing Modes

    Register Indirect Addressing Mode

    Limitation:

    Since R0 and R1 are the only registers used (8-bit wide), their use is limited to accessing any information in the internal RAM. To access an externally connected RAM or on-chip ROM, we need a 16-bit pointer.

  • 8051 Addressing Modes

    Indexed Addressing Mode

    Used to access data located in ROM space of 8051.The instruction used for this purpose is

    MOVC A, @A+DPTR

    Because the data is stored in ROM of 8051, it uses MOVC instead of MOV.The contents of A are added to the 16-bit registers DPTR to form the 16-bit address of the needed data.
  • Review Questions

    The instruction MOV A, 40H uses ___ addressing mode. Why?What address is assigned to register R2 of bank 0?What address is assigned to register R2 of bank 2?What address is assigned to register A?Which registers are allowed to be used for register indirect addressing mode if the date is in on-chip RAM?