1 / 88

Now we begin our exploration in the assembly language

Now we begin our exploration in the assembly language. Chapter 4. Chapter 4: Assembly Language-Addressing Modes( 寻址方式 ). Chapter 4:. 4.1 Prerequisite knowledge about instructions 4.2 Data Addressing Modes 4.3 Program Memory-Addressing Modes 4.4 Stack Memory-Addressing Modes.

meena
Download Presentation

Now we begin our exploration in the assembly language

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. Now we begin our exploration in theassembly language 川大软件学院左航

  2. Chapter 4 川大软件学院左航

  3. Chapter 4:Assembly Language-Addressing Modes(寻址方式)

  4. Chapter 4: • 4.1 Prerequisite knowledge about instructions • 4.2 Data Addressing Modes • 4.3 Program Memory-Addressing Modes • 4.4 Stack Memory-Addressing Modes 川大软件学院左航

  5. 4.1 Prerequisite knowledge about instructions 川大软件学院左航

  6. 4.1 Prerequisite knowledge about instructions • Default expression • Segment register ---- stored segment base address • imm/im ---- immediate data • DST ---- destination operand • SRC ---- source operand • R8/R16/R32----register of 8/16/32 bits • mm ---- memory data 川大软件学院左航

  7. 4.1 Prerequisite knowledge about instructions • MOV AX, BX opcode operand operand CS 1,2,3 operand SS/DS 川大软件学院左航

  8. 4.1 Prerequisite knowledge about instructions • We will use the most common instruction “MOV” to illustrate data addressing modes. Copy content DST SRC MOV operand1 operand2 川大软件学院左航

  9. 4.1 Prerequisite knowledge about instructions • MOV X,Y X = Y opcode operand1 operand2 2.register 3.memory 1.immediate data 川大软件学院左航

  10. 4.1 Prerequisite knowledge about instructions • 1. Operand is directly in the instructions. • ----immediately addressing • 2. Operand is stored in a register in CPU. • ----register addressing • 3. Operand is stored in the memory. • ----the address is combined by segment address and offset address. 川大软件学院左航

  11. 4.2 Data Addressing Modes 川大软件学院左航

  12. 4.2 Data Addressing Modes • 4.2.2 Immediate addressing • 4.2.3 Direct data addressing • 4.2.1 Register addressing • 4.2.4 Register indirect addressing • 4.2.6 Register relative addressing • 4.2.5 Base-plus-index addressing • 4.2.7 Base relative-plus-index addressing • 4.2.8 Scaled-index addressing • 4.2.9 Data Structures 川大软件学院左航

  13. 4.2.2 Immediate addressing 川大软件学院左航

  14. 4.2.2 Immediate addressing • MOV AX,1234H AX = AX + 1234H opcode operand1 operand2 mem cpu ? 川大软件学院左航

  15. FFFFFH 9FFFFH CS + IP CS 90000H 3FFFFH MEMMORY 1M DS 30000H 1FFFFH SS 10000H 00000H 川大软件学院左航

  16. 4.2.2 Immediate addressing • Example: • MOV AX,1234H AX 00105 Code segment 00104 00103 川大软件学院左航

  17. 4.2.2 Immediate addressing • Definition: • Operand2 is a immediate data or an expression whose value can be figure out. It’s a constant data. • Example: • MOV AX,100H AX ← 100H • MOV EAX,0A5FH EAX ←0A5FH • MOV AH,1101B AH ←1101B • MOV AL,’A’---------AL ← 41H 川大软件学院左航

  18. 4.2.2 Immediate addressing • A simple program .MODEL TINY (only cs) 0000 .CODE .STARTUP 0100 B8 0000 MOV AX,0 0103 B8 0000 MOV BX,0000H 0106 B9 0000 MOV CX,0 0109 8B F0 MOV SI,AX .EXIT (return to DOS) END 川大软件学院左航

  19. 4.2.3 Direct data addressing 川大软件学院左航

  20. 4.1 Prerequisite knowledge about instructions • MOV AX,NUM AX = AX + NUM opcode operand1 operand2 川大软件学院左航

  21. FFFFFH 9FFFFH Physical address = segment base address + offset =DS + 2000H Address of NUM CS 90000H 3FFFFH MEMMORY 1M Content of NUM DS 30000H 1FFFFH SS 10000H 00000H 川大软件学院左航

  22. 4.2.3 Direct data addressing • A. Direct addressing • B. Displacement Addressing 川大软件学院左航

  23. 4.2.3 Direct data addressing • A. Direct addressing • Definition: Transfer data between a memory location, located within the data segment and the AX register. P79 • Example: • MOV AX, NUM AX ←DS:[NUM] • MOV TWO,AX DS:[TWO] ←AX • MOV ES:[2000H],AL ES:[2000] ←AL 川大软件学院左航

  24. 4.2.3 Direct data addressing NUM DW 3050H MOV AX,NUM DS NUM Code segment 30000 1 + 2000 32000 2 3 30002 data segment AX 32001 32000 4 川大软件学院左航

  25. 4.2.3 Direct data addressing • SS+SP/ESP or SS+BP/EBP • DS+ memory offset • MOV ES:[2000H],AL ES:[2000] ←AL 川大软件学院左航

  26. 4.2.3 Direct data addressing • B. Displacement Addressing • It is almost identical to direct addressing, except that the instruction is four bytes wide instead of three. • And the registers used aren’t AX. • MOV AX, NUM AX ←DS:[NUM] • We need not consider about the instruction bytes now, so ignore it. • MOV CX,NUM 川大软件学院左航

  27. 4.2.1 Register addressing 川大软件学院左航

  28. 4.2.1 Register addressing • Definition: • All the operands are in registers(8/16/32b). It’s a variable data. • Example: • MOV AL,BL (8) AL ← BL • MOV DS,AX (16) DS ← AX • MOV SP,BP (16) SP ← BP • MOV ECX,EDX ECX ←EDX 川大软件学院左航

  29. 4.2.1 Register addressing • Special Example: • MOV EAX,BX • Wrong, mixed size in MOV (32 ,16) • MOV DS,AX • Right • MOV ES,DS • Wrong, segment-to-segment • MOV CS,BX or MOV IP,BX • Wrong, CS or IP Register can’t be DST 川大软件学院左航

  30. 4.2.4 Register indirect addressing • MOV AX,BX • MOV AX,[BX] 川大软件学院左航

  31. 4.2.4 Register indirect addressing • Definition: • physical address = (BP,BX)/(DI,SI) + base address (segment registers) • MOV AX,[BX] • memory data • offset address is stored BX、SI、DI 、 BP. • [ ] means indirect addressing • MOV AX,[DX]wrong 川大软件学院左航

  32. 4.2.4 Register indirect addressing MOV AX,[SI] DS Code segment SI 20000 1 + 1000 21000 20002 21001 data segment AX 2 21000 3 川大软件学院左航

  33. 4.2.4 Register indirect addressing • A. DS --------[BX]、[SI]、[DI] • Example: MOV AX,[BX] AX← (DS:[BX]) MOV AH,[DI] AH← (DS:[DI]) Base address + offset 川大软件学院左航

  34. 4.2.4 Register indirect addressing • B. SS-------- [BP] • Example: MOV AX,[BP]AX← (SS:[BP]) • MOV ES:[2000H],AL [ES:[2000]] ←AL Base address + offset 川大软件学院左航

  35. 4.2.4 Register indirect addressing • Example: MOV [DI],10H cause ambiguous DI = 0200H,DS =1000H MOV BYTE PTR [DI],10H MOV WORD PTR [DI],10H 10200H 10201H 10200H 川大软件学院左航

  36. 4.2.4 Register indirect addressing • MOV [DI],[BX] • Wrong , memory to memory is not permitted. 川大软件学院左航

  37. 4.2.4 Register indirect addressing • Simple program P83 3-6 .MODEL SMALL (DATA & CODE) .DATA AGAIN: DATAS DW 50 DUP (?) MOV AX,ES:[046CH] .CODE MOV [BX],AX .STARTUP INC BX INC BX MOV AX,0 LOOP AGAIN MOV ES,AX .EXIT MOV BX,OFFSET DATAS END MOV CX,50 川大软件学院左航

  38. 10032H Data Segment DS = 1000H 10031H DB 50 DUP (?) 10001H DATAS = 0 10000H 川大软件学院左航

  39. 4.2.6 Registerrelativeaddressing 川大软件学院左航

  40. 4.2.6 Register relative addressing • Definition: • physical address = displacement (位移量) + (BP,BX)/(DI,SI) + base address (segment registers) • Examples: • MOV AX,[SI+100H] AX←DS:[SI+100H] 川大软件学院左航

  41. 4.2.6 Register relative addressing • MOV AX,[SI+100H] Code segment DS SI AX 30601 data segment 30600 川大软件学院左航

  42. 4.2.6 Register relative addressing • Examples: • MOV AX,[DI+100H] AX ←DS:[DI+100H] • MOV ARRAY[SI],BL DS:[ARRAY+SI] ←BL • MOV LIST[SI+2],CL DS:[LIST+SI+2] ←CL • MOV CX,[BP+10H] CX ←SS:[BP+10H] 川大软件学院左航

  43. 4.2.6 Register relative addressing • Simple program p88 3-8 • .MODEL SMALL MOV DI,10H • .DATA MOV AL,ARRAY[DI] • ARRAY DB 16 DUP (?) MOV DI,20H • DB 29H MOV ARRAY[DI],AL • DB 30 DUP (?) .EXIT • .CODE END • .STARTUP 川大软件学院左航

  44. P85 3-7 FFFFFH DB 30 DUP (?) DB 29H OFFSET = 10H = ARRAY + 16 OFFSET = 0FH = ARRAY + 15 ARRAY DB 16 DUP (?) DS + 01H DS = 30000H ARRAY OFFSET = 0 OFFSET 00000H 川大软件学院左航

  45. MOV AL, ARRAY[DI] ---- ARRAY+DI+DS*10H 0002EH DB 30 DUP (?) 00011H Data Segment DS =0000H DB 29H 00010H 0000FH DB 16 DUP (?) 00001H ARRAY = 0 00000H 川大软件学院左航

  46. 4.2.5 Base-plus-index addressing 川大软件学院左航

  47. 4.2.5 Base-plus-index addressing • Definition: • memory data. • offset = BP/BX(基址)+ DI/SI (变址) • Physical address = offset + DS/SS • Examples: MOV CX,[BX+DI] CX ←DS:[BX+DI] 16 MOV CH,[BP+SI] CH ←SS:[BP+SI] 8 川大软件学院左航

  48. 4.2.5 Base-plus-index addressing • MOV AX,[BX+SI] Code segment DS BX SI AX 31701 data segment 31700 川大软件学院左航

  49. 4.2.5 Base-plus-index addressing • Examples: MOV [BX+SI],SP DS:[BX+SI] ← SP 16 MOV [BP+DI],AH SS:[BP+DI] ←AH 8 MOV CL,[EDX+EDI] CL ←DS:[EDX+EDI] 8 MOV [EDX+EDI],ECX DS:[EDX+EDI]←ECX 32 川大软件学院左航

  50. 4.2.5 Base-plus-index addressing • Simple program p85 3-7 • .DOMEL SMALL MOV BX, OFFSET ARRAY • .DATA MOV DI,10H • ARRAY DB 16 DUP (?) MOV AL,[BX+DI] • DB 29H MOV DI,20H • DB 30 DUP (?) MOV [BX+DI],AL • .CODE .EXIT • .STARTUP END • DS+OFFSET ARRAY + 10H 川大软件学院左航

More Related