際際滷

際際滷Share a Scribd company logo
MICROCONTROLLERS
           8051
 Created By: Sachin Bhalavat
             (Elect. & Comm. Engg.)
             profspbhalavat@gmail.com
8051 addressing modes
 The first byte of an instruction is known as the opcode
  (operation code) because this is the byte that is decoded by
  the processor - from this code the processor can work out
  what operation it must perform.
 For a one-byte instruction there is only the opcode.
 For a two-byte instruction the second byte is the operand.
 The operand can be data or an 8-bit address.
 For a three-byte instruction the second and third bytes make
  up the operand.
 A two-byte operand is usually a 16-bit address, as we shall see
  when we look at long addressing
The five addressing modes are:

Immediate addressing modes

Register addressing modes

Direct addressing modes

Indirect addressing modes

Register specific addressing mode
 Immediate addressing is only use when the data to be read is a
constant.
 The data is numeric constant in the operand indicated by a # sign
 Useful for getting constants into registers.
 For example, if your program needed to perform some calculations
based on the number of weeks in the year, you could use immediate
addressing to load the number 52 (34H) into a register and then perform
arithmetic operations upon this data.
               MOV R0, #34H
 The above instruction is an example of immediate addressing. It moves
the data 34H into R0.
 The has symbol (#) is used for this purpose (whenever the assembler
sees # before a number it knows this is immediate addressing).
 This is a two-byte instruction.
 Data can be 16-bits when dealing with the DPTR register .
             MOV DPTR, #2500H
 Direct access to eight registers (R0-R7).
 There are 4 banks of registers accessible through register
  addressing.
 Only one bank can be accessed at a time controllable through bit
  RS0 and RS1 of the PSW.
 Often we need to move data from a register into the accumulator
  so that we can perform arithmetic operations upon it. For
  example, we may wish to move the contents of R5 into the
  accumulator.
                MOV A, R5
 This is an example of register addressing. It moves data from R5
  (in the currently selected register bank) into the accumulator.
 Direct addressing is Used to access any on-chip RAM location, General
  purpose registers, Control registers or SFRs, which can be addressed by
  address or name.
           MOV A, 67
    The above instruction moves the data in location 67H into the
  accumulator.
 Note the difference between this and immediate addressing. Immediate
  addressing uses the data, which is immediately after the instruction.
  With direct addressing, the operand is an address.
 The data to be operated upon is stored in that address.
 The assembler realises this is an address and not data because there is
  no hash symbol before it.
 R0 or R1 hold the location of the internal RAM
 location. Indicated by the @ sign.
 It Can be used for accessing external memory, where R0 and R1 point to
  external memory locations 00H to FFH.
 Example:
                            MOV A, @Ri
 where Ri is either R0 or R1. Now, we can read the contents of location
  30H through indirect addressing:
                            MOV R0, #30H
                            MOV A, @R0
 The first instruction is an example of immediate addressing where the
  data 30H is placed in R0. The second instruction is indirect addressing. It
  moves the contents of location 30H into the accumulator.
 In this addressing mode the instruction refer to a
  specific register such as accumulator or a data
  pointer.
 Example:
    DA A :decimal adjust accumulator for addition
    RR A :rotate the content of accumulator to the right
    SWAP A:swap the nibble within the accumulator

More Related Content

8051 addressing modes

  • 1. MICROCONTROLLERS 8051 Created By: Sachin Bhalavat (Elect. & Comm. Engg.) profspbhalavat@gmail.com
  • 3. The first byte of an instruction is known as the opcode (operation code) because this is the byte that is decoded by the processor - from this code the processor can work out what operation it must perform. For a one-byte instruction there is only the opcode. For a two-byte instruction the second byte is the operand. The operand can be data or an 8-bit address. For a three-byte instruction the second and third bytes make up the operand. A two-byte operand is usually a 16-bit address, as we shall see when we look at long addressing
  • 4. The five addressing modes are: Immediate addressing modes Register addressing modes Direct addressing modes Indirect addressing modes Register specific addressing mode
  • 5. Immediate addressing is only use when the data to be read is a constant. The data is numeric constant in the operand indicated by a # sign Useful for getting constants into registers. For example, if your program needed to perform some calculations based on the number of weeks in the year, you could use immediate addressing to load the number 52 (34H) into a register and then perform arithmetic operations upon this data. MOV R0, #34H The above instruction is an example of immediate addressing. It moves the data 34H into R0. The has symbol (#) is used for this purpose (whenever the assembler sees # before a number it knows this is immediate addressing). This is a two-byte instruction. Data can be 16-bits when dealing with the DPTR register . MOV DPTR, #2500H
  • 6. Direct access to eight registers (R0-R7). There are 4 banks of registers accessible through register addressing. Only one bank can be accessed at a time controllable through bit RS0 and RS1 of the PSW. Often we need to move data from a register into the accumulator so that we can perform arithmetic operations upon it. For example, we may wish to move the contents of R5 into the accumulator. MOV A, R5 This is an example of register addressing. It moves data from R5 (in the currently selected register bank) into the accumulator.
  • 7. Direct addressing is Used to access any on-chip RAM location, General purpose registers, Control registers or SFRs, which can be addressed by address or name. MOV A, 67 The above instruction moves the data in location 67H into the accumulator. Note the difference between this and immediate addressing. Immediate addressing uses the data, which is immediately after the instruction. With direct addressing, the operand is an address. The data to be operated upon is stored in that address. The assembler realises this is an address and not data because there is no hash symbol before it.
  • 8. R0 or R1 hold the location of the internal RAM location. Indicated by the @ sign. It Can be used for accessing external memory, where R0 and R1 point to external memory locations 00H to FFH. Example: MOV A, @Ri where Ri is either R0 or R1. Now, we can read the contents of location 30H through indirect addressing: MOV R0, #30H MOV A, @R0 The first instruction is an example of immediate addressing where the data 30H is placed in R0. The second instruction is indirect addressing. It moves the contents of location 30H into the accumulator.
  • 9. In this addressing mode the instruction refer to a specific register such as accumulator or a data pointer. Example: DA A :decimal adjust accumulator for addition RR A :rotate the content of accumulator to the right SWAP A:swap the nibble within the accumulator