1 / 40

Introduction to Micro Controllers & Embedded System Design Addressing Mode

Introduction to Micro Controllers & Embedded System Design Addressing Mode. Department of Electrical & Computer Engineering Missouri University of Science & Technology hurson@mst.edu. Introduction to Micro Controllers & Embedded System Design.

Download Presentation

Introduction to Micro Controllers & Embedded System Design Addressing Mode

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Micro Controllers&Embedded System DesignAddressing Mode Department of Electrical & Computer Engineering Missouri University of Science & Technology hurson@mst.edu A.R. Hurson

  2. Introduction to Micro Controllers & Embedded System Design Note, this unit will be covered in two lectures. In case you pre-test it, then you have the following options: 1) Take the early test and start module5 2) Study the supplement module (supplement.module4) 3) Act as a helper to help other students in studying module1 Note, options 2 and 3 have extra credits as noted in course outline.

  3. Introduction to Micro Controllers & Embedded System Design  Enforcement of background Glossary of prerequisite topics No Familiar with the topics? Review background for this module Yes Take Test At the end: take exam, record the score, impose remedial action if not successful No Pass? Remedial action  Yes Glossary of topics Current Module No Familiar with the topics? Take the Module Yes Take Test No Pass? Yes Options Lead a group of students in this module (extra credits)? Study next module? Study more advanced related topics (extra credits)? Extra Curricular activities

  4. 8051 supports the following addressing modes: • Register • Implied • Direct • Indirect • Immediate • Relative • Absolute • Long • Indexed A.R. Hurson

  5. Register addressing • In 8051 programmer has access to eight “working registers” numbered R0 to R7. • Three least significant bits of op.code are used to specify a register. • The 8051 assembly language indicates register addressing with the symbol Rn (0  n  7). A.R. Hurson

  6. Register addressing • Example ADD A, R7 1 1 1 0 1 1 1 1 Op.code Op.code register Register Instruction format A.R. Hurson

  7. Register addressing • Example: Is MOV R4, R7a valid instruction? No. Note: We can move data between accumulator and Rn, 0  n  7 but we cannot move data between Rn registers. A.R. Hurson

  8. Register addressing • Note: The source and destination registers must match in size. Hence, MOV DPTR, A will give an error. • How to move a large value to registers? See the following: MOV DPTR, #25F5H MOV R7, DPL MOV R6, DPH A.R. Hurson

  9. Register addressing Note: MOV A, R7 is the same as MOV A, 7 A.R. Hurson

  10. Register addressing • Note: we can move data between accumulator and Rn ( 0  n  7), but we cannot move data between Rn registers directly. • As the result, the following instruction is illegal. MOV R5 , R7 A.R. Hurson

  11. Implied • Some instructions are referring to specific register such as A (accumulator), DPTR (data pointer), PC (program counter), and B register so address bits are not needed. In another words, op.code indicates the register involved in the operation. • Example INC DPTR MUL AB A.R. Hurson

  12. Direct addressing • Direct addressing allows access to any on-chip variable or hardware register. An additional byte is appended to the op.code specifying the location to be used. • Example MOV P1, A Direct addressing Op.code Instruction format A.R. Hurson

  13. Direct addressing • Example MOV R7, 40H ; Content of RAM location 40H is saved in R7 MOV 56H, A ; Content of accumulator is saved in RAM location 56H MOV A, R2 ; Content of R2 is saved in accumulator MOV A, 2 ; Content of R2 is saved in accumulator MOV A, #2 ; Accumulator is initialized by 2 MOV A, 55H ; Content of RAM location 55H is saved in accumulator A.R. Hurson

  14. Indirect addressing • In 8051, R0 and R1 may operate as a “pointer” register. In this case, the low order bit of op.code indicates which register. • In 8051assembly language, indirect addressing is identified as “@” preceding either R0 or R1. A.R. Hurson

  15. Indirect addressing • Example: Assume R1 contains 40H and internal memory address 40H contains 55H, then the instruction MOV A, @R1 moves 55H into the accumulator Op.code Instruction format R0 or R1 A.R. Hurson

  16. Indirect addressing • The following code clears RAM locations at addresses 60H to 7FH: MOV R0, #60H LOOP: MOV @R0, #0 INC R0 CJNE R0, #80H, Loop    A.R. Hurson

  17. Immediate addressing • In assembly language of 8051, immediate addressing is identified by “#” symbol. The operand may be a numeric constant, a symbolic variable, or an arithmetic expression using constant, symbols, and operators. Assembler calculates the expression and substitutes the result into the instruction. Immediate data Op.code Instruction format A.R. Hurson

  18. Immediate addressing • Example: Is MOV DPTR, #68975 a valid instruction? No! 68975 > 65535 is too large Note: We can move data between accumulator and Rn, 0  n  7 but we cannot move data between Rn registers. A.R. Hurson

  19. Immediate addressing • Example: MOV A, #12 • Note: There is just one exception when initializing the data pointer, we need a 16-bit constant, therefore MOV DPTR, #8000H is a 3-byte instruction with a 16-bit constant 8000H. A.R. Hurson

  20. Immediate addressing COUNT EQU 30    MOV R4, #COUNT ; R4 = 1EH MOV DPTR, #MYDATA ; DTPR = 200H ORG 200H MYDATA: DB “America” A.R. Hurson

  21. Example: Write a program to copy value 55H into RAM locations 40H to 45H using; • Direct addressing mode • Register indirect addressing mode • With a loop A.R. Hurson

  22. Direct addressing mode MOV A, #55H ; Load accumulator with 55H MOV 40H, A ; Load accumulator to location 40H MOV 41H, A ; Load accumulator to location 41H MOV 42H, A ; Load accumulator to location 42H MOV 43H, A ; Load accumulator to location 43H MOV 44H, A ; Load accumulator to location 44H A.R. Hurson

  23. Register indirect addressing mode MOV A, #55H ; Load accumulator with 55H MOV R0, #40H ; Load the pointer MOV @R0, A ; Load A to location pointed by R0 INC R0 ; Increment pointer MOV @R0, A ; Load A to location pointed by R0 INC R0 ; Increment pointer MOV @R0, A ; Load A to location pointed by R0 INC R0 ; Increment pointer MOV @R0, A ; Load A to location pointed by R0 INC R0 ; Increment pointer MOV @R0, A ; Load A to location pointed by R0 INC R0 ; Increment pointer A.R. Hurson

  24. With a loop MOV A, #55H ; Load accumulator with 55H MOV R0, #40H ; Load the pointer MOV R2, #05 ; Load the loop counter AGAIN: MOV @R0, A ; Load A to location pointed by R0 INC R0 ; Increment pointer DJNZ R2, AGAIN ; Repeat until counter is zero A.R. Hurson

  25. Analyze the following program ORG 0000H MOV DPTR, #200H CLR A MOVC A, @A+DPTR ; Load the pointer MOV R0, A ; Load the loop counter INC DPTR CLR A MOVC A, @A+DPTR MOV R1, A INC DPTR MOVC A, @A+DPTR MOV R2, A HERE: SJMP HERE ; Infinite loop ORG 200H MYDATA: DB “USA” ; Data is stored at address 200H END ; End of program A.R. Hurson

  26. Analyze the following program ORG 0000H MOV DPTR, #MYDATA MOV R0, #40H MOV R2, #7 BACK: CLR A MOVC A, @A+DPTR MOV @R0, A INC DPTR INC R0 DJNZ R2 , BACK HERE: SJMP HERE ORG 250H MYDATA: DB “AMERICA” ; Data is stored at address 250H END ; End of program A.R. Hurson

  27. Analyze the following program ORG 0000H MOV DPTR, #MYDATA MOV R0, #40H BACK: CLR A MOVC A, @A+DPTR JZ HERE MOV @R0, A INC DPTR INC R0 SJMP BACK HERE: SJMP HERE ORG 250H MYDATA: DB “AMERICA”, 0 ; Data is stored at address 250H END ; End of program A.R. Hurson

  28. Analyze the following program ORG 0000H MOV DPTR, #300H MOV A, #0FFH MOV P1, A BACK: MOV A, P1 MOVC A, @A+DPTR MOV P2, A SJMP BACK ORG 300H XSQRT: DB 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 END A.R. Hurson

  29. Relative addressing • This addressing mode is used with certain jump instructions. A relative address is an 8-bit signed value which is added to the contents of the program counter to form address of the next instruction to be fetched and executed. • Naturally, the range for jump is -128 to +127 locations. Relative offset Op.code Instruction format A.R. Hurson

  30. Relative addressing • Example: Assume label THREE represents an instruction at location 1040H and instruction SJMP THREE is in memory location 1000H and 1001H, then the assembler assigns a relative offset of 3EH as byte-two of the instruction since 1002H + 3EH = 1040H A.R. Hurson

  31. Calculating off set for Relative addressing PC SJMP 0107H  A.R. Hurson

  32. Calculating off set for Relative addressing  SJMP 2038H PC A.R. Hurson

  33. Absolute addressing • Absolute addressing is just used with ACALL and AJMP instructions. These 2-byte instructions allow branching within the current 2K page of code memory by providing the 11 least significant bits of destination address in op.code (i.e., A10-A8 and byte 2 of instruction A7-A0). A7-A0 Op.code A10-A8 Instruction format A.R. Hurson

  34. Absolute addressing • The upper five bits of the destination address are the current value of the upper five bits of program counter. Therefore, the next instruction after the branch and the destination instruction must be within the same 2K page. A.R. Hurson

  35. Absolute addressing FFFF F800 2K page31 32 2K pages. Within each the upper 5 address bits are common. 17FF 1000 2K page2 0FFF 0800 2K page1 07FF 0000 2K page0 A.R. Hurson

  36. Long addressing • Long addressing is used with LCALLand LJMPinstructions. These instruction are 3 bytes long. Bytes 2 and 3 form the 16-bit destination address. A7-A0 A15-A8 Op.code Instruction format A.R. Hurson

  37. Index addressing • Index addressing uses a base register (either the program counter or the data pointer) and an offset (the accumulator) in forming the effective address for JMP or MOVC instructions. • Example: MOVC A, @A+PC PC or DPTR + ACC = effective address Offset Base register A.R. Hurson

  38. Special Function Registers (SFR) A.R. Hurson

  39. Special Function Registers (SFR) A.R. Hurson

  40. Special Function Registers (SFR) * Bit addressable A.R. Hurson

More Related