UMBC A B M A L T F O U M B C I M Y O R T 1 (Feb. - - PowerPoint PPT Presentation

umbc
SMART_READER_LITE
LIVE PREVIEW

UMBC A B M A L T F O U M B C I M Y O R T 1 (Feb. - - PowerPoint PPT Presentation

Systems Design & Programming 80x86 Assembly II CMPE 310 Data Addressing Modes Base-Plus-Index addressing: Effective address computed as: seg_base + base + index. Base registers: Holds starting location of an array. ebp (stack) ebx


slide-1
SLIDE 1

Systems Design & Programming 80x86 Assembly II CMPE 310 1 (Feb. 9, 2002)

UMBC

U M B C U N I V E R S I T Y O F M A R Y L A N D B A L T I M O R E C O U N T Y 1 9 6 6

Data Addressing Modes Base-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.

slide-2
SLIDE 2

Systems Design & Programming 80x86 Assembly II CMPE 310 2 (Feb. 9, 2002)

UMBC

U M B C U N I V E R S I T Y O F M A R Y L A N D B A L T I M O R E C O U N T Y 1 9 6 6

Data Addressing Modes Base-Plus-Index addressing: eax ebx ecx edx esp ebp edi esi 1 0 0 0 cs ds es ss A B 0 3 0 0 1 0 Memory F012AB03 0 1 0 0 + 1010H + mov edx, [ebx+edi] F 0 1 2 0 0 0 0 Seg Base Paging Physical Address Trans.

slide-3
SLIDE 3

Systems Design & Programming 80x86 Assembly II CMPE 310 3 (Feb. 9, 2002)

UMBC

U M B C U N I V E R S I T Y O F M A R Y L A N D B A L T I M O R E C O U N T Y 1 9 6 6

Data Addressing Modes Register 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.

slide-4
SLIDE 4

Systems Design & Programming 80x86 Assembly II CMPE 310 4 (Feb. 9, 2002)

UMBC

U M B C U N I V E R S I T Y O F M A R Y L A N D B A L T I M O R E C O U N T Y 1 9 6 6

Data Addressing Modes Base Relative-Plus-Index addressing: 0 0 2 0 A 3 1 6 0 0 1 0 Memory A316 1 0 0 0 + + MOV ax, [ebx+esi+100H] + 100H 0 0 0 0 eax ebx ecx edx esp ebp edi esi cs ds es ss Seg Base Paging Trans. 1030H

slide-5
SLIDE 5

Systems Design & Programming 80x86 Assembly II CMPE 310 5 (Feb. 9, 2002)

UMBC

U M B C U N I V E R S I T Y O F M A R Y L A N D B A L T I M O R E C O U N T Y 1 9 6 6

Data/Code Addressing Modes Scaled-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 Indirect Direct: Absolute jump address is stored in the instruction following the

  • pcode.

mov eax, [ebx+4*ecx] ;Data segment DWORD copy. ;Whow ! mov eax, [ARRAY+4*ecx] ;Std array addressing. mov [eax+2*edi-100H], cx

slide-6
SLIDE 6

Systems Design & Programming 80x86 Assembly II CMPE 310 6 (Feb. 9, 2002)

UMBC

U M B C U N I V E R S I T Y O F M A R Y L A N D B A L T I M O R E C O U N T Y 1 9 6 6

Code Addressing Modes An 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 A 0000 Opcode Offset (low) Segment(low) Segment(high) Offset (high) 0000 00 10

slide-7
SLIDE 7

Systems Design & Programming 80x86 Assembly II CMPE 310 7 (Feb. 9, 2002)

UMBC

U M B C U N I V E R S I T Y O F M A R Y L A N D B A L T I M O R E C O U N T Y 1 9 6 6

Code Addressing Modes Indirect: 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.

slide-8
SLIDE 8

Systems Design & Programming 80x86 Assembly II CMPE 310 8 (Feb. 9, 2002)

UMBC

U M B C U N I V E R S I T Y O F M A R Y L A N D B A L T I M O R E C O U N T Y 1 9 6 6

Stack Addressing Modes The stack is used to hold temporary variables and stores return addresses for procedures. 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,edi pop eax ;Pops 4 bytes.