Thiết kế và lập trình hệ thống - Chương
Systems Design & Programming 80x86 Assembly II CMPE 3101 (Feb. 9, 2002)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Data Addressing ModesBase-Plus-Index addressing:Effective address computed as:seg_base + base + index.Base registers: Holds starting location of an array.• ebp (stack)• ebx (data)• Any 32-bit register except esp.Index registers: Holds offset location.• edi• esi• Any 32-bit register except esp.mov dl, [eax+ebx];EAX as base, EBX as index.mov ecx,[ebx+edi];Data segment copy.mov ch, [ebp+esi];Stack segment copy. Systems Design & Programming 80x86 Assembly II CMPE 3102 (Feb. 9, 2002)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Data Addressing ModesBase-Plus-Index addressing:eaxebxecxedxespebpediesi1 0 0 0csdsesssA B 0 30 0 1 0MemoryF012AB030 1 0 0+1010H+mov edx, [ebx+edi]F 0 1 20 0 0 0SegBasePagingPhysical AddressTrans. Systems Design & Programming 80x86 Assembly II CMPE 3103 (Feb. 9, 2002)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Data Addressing ModesRegister Relative addressing:Effective address computed as:seg_base + base + constant.Same default segment rules apply with respect to ebp, ebx, edi and esi.Displacement constant is any 32-bit signed value.Base Relative-Plus-Index addressing:Effective address computed as:seg_base + base + index + constant.Designed to be used as a mechanism to address a two-dimensional array.mov edx, [LIST+esi+2];Both LIST and 2 are constants.mov eax, [ebx+1000H];Data segment copy.mov [ARRAY+esi], BL;Constant is ARRAY.mov edx, [LIST+esi-2];Subtraction.mov [LIST+ebp+esi+4], dh;Stack segment copy.mov dh, [ebx+edi+20H];Data segment copy.mov ax, [FILE+ebx+edi];Constant is FILE.mov eax, [FILE+ebx+ecx+2];32-bit transfer. Systems Design & Programming 80x86 Assembly II CMPE 3104 (Feb. 9, 2002)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Data Addressing ModesBase Relative-Plus-Index addressing:0 0 2 0A 3 1 60 0 1 0MemoryA3161 0 0 0++MOV ax, [ebx+esi+100H]+100H0 0 0 0eaxebxecxedxespebpediesicsdsesssSegBasePagingTrans.1030H Systems Design & Programming 80x86 Assembly II CMPE 3105 (Feb. 9, 2002)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Data/Code Addressing ModesScaled-Index addressing:Effective address computed as:seg_base + base + constant*index.Code Memory-Addressing Modes:Used in jmp and call instructions.Three forms: Direct PC-Relative IndirectDirect:Absolute jump address is stored in the instruction following theopcode.mov eax, [ebx+4*ecx];Data segment DWORD copy.;Whow !mov eax, [ARRAY+4*ecx];Std array addressing.mov [eax+2*edi-100H], cx Systems Design & Programming 80x86 Assembly II CMPE 3106 (Feb. 9, 2002)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Code Addressing ModesAn intersegment jump:This far jmp instruction loads cs with 1000H and eip with 00000000H.A far call instruction is similar.PC-Relative:A displacement is added to the EIP register.This constant is encoded into the instruction itself, as above.Intrasegment jumps: Short jumps use a 1-byte signed displacement. Near jumps use a 4-byte signed displacement.The assembler usually computes the displacement and selects the appro-priate form.E A0000OpcodeOffset (low)Segment(low)Segment(high)Offset (high)00000010 Systems Design & Programming 80x86 Assembly II CMPE 3107 (Feb. 9, 2002)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Code Addressing ModesIndirect:Jump location is specified by a register.There are three forms: Register:Any register can be used: eax, ebx, ecx, edx, esp, ebp, edi or esi. Register Indirect:Intrasegment jumps can also be stored in the data segment. Register Relative:jmp eax;Jump within the code seg.jmp [ebx];Jump address in data seg.jmp [edi+2]jmp [TABLE+ebx];Jump table. Systems Design & Programming 80x86 Assembly II CMPE 3108 (Feb. 9, 2002)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Stack Addressing ModesThe stack is used to hold temporary variables and stores return addresses forprocedures.push and pop instructions are used to manipulate it.call and ret also refer to the stack implicitly.Two registers maintain the stack, esp and ss.A LIFO (Last-in, First-out) policy is used.The stack grows toward lower address.Data may be pushed from any of the registers or segment registers.Data may be popped into any register except cs.popfd;Pop doubleword for stack to EFLAG.pushfd;Pushes EFLAG register.push 1234H;Pushes 1234H.push dword [ebx];Pushes double word in data seg.pushad;eax,ecx,edx,ebx,esp,ebp,esi,edipop eax;Pops 4 bytes. . Assembly II CMPE 3101 (Feb. 9, 200 2)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Data Addressing ModesBase-Plus-Index addressing:Effective. Assembly II CMPE 3102 (Feb. 9, 200 2)UMBCU M B CUNIVERSITY OF MARYLAND BALTIMORE COUNTY1 9 6 6Data Addressing ModesBase-Plus-Index addressing:eaxebxecxedxespebpediesi1