Lecture 6

# special cases can use any combinamon of d rb ri and s

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for accessing memory in mov (and other) instrucMons can be computed in several diﬀerent ways Most General Form: D(Rb,Ri,S)   Mem[Reg[Rb] + S*Reg[Ri] + D]   D: Constant “displacement” 1, 2, or 4 bytes   Rb: Base register: Any of the 8/16 integer registers   Ri: Index register: Any, except for %esp or %rsp   Unlikely you’d use %ebp, either   S: Scale: 1, 2, 4, or 8 (why these numbers?) Special Cases: can use any combinaMon of D, Rb, Ri and S (Rb,Ri) Mem[Reg[Rb]+Reg[Ri]] D(Rb,Ri) Mem[Reg[Rb]+Reg[Ri]+D] (Rb,Ri,S) Mem[Reg[Rb]+S*Reg[Ri]]   x86 University of Washington Address ComputaMon Examples %edx 0xf000 %ecx 0x100 (Rb,Ri) D(,Ri,S) (Rb,Ri,S) D(Rb) Mem[Reg[Rb]+Reg[Ri]] Mem[S*Reg[Ri]+D] Mem[Reg[Rb]+S*Reg[Ri]] Mem[Reg[Rb] +D] Expression Address ComputaMon Address 0x8(%edx) 0xf000 + 0x8 0xf008 (%edx,%ecx) 0xf000 + 0x100 0xf100 (%edx,%ecx,4) 0xf000 + 4*0x100 0xf400 0x80(,%edx,2) 2*0xf000 + 0x80 0x1e080 x86 University of Washington Address ComputaMon InstrucMon   leal Src,Dest   Src is address mode expression   Set Dest to address computed by expression (lea stands for load eﬀec7ve address)   Example: leal (%edx,%ecx,4), %eax     Uses   CompuIng addresses without a memory reference   E.g., translaIon of p = &amp;x[i];   CompuIng arithmeIc expressions of the form x + k*i   k = 1, 2, 4, or 8 x86 University of Washington Some ArithmeMc OperaMons   Two Operand (Binary) InstrucMons: Format Computa&lt;on addl Src,Dest Dest = Dest + Src subl Src,Dest Dest = Dest - Src imull Src,Dest Dest = Dest * Src sall Src,Dest Dest = Dest &lt;&lt; Src Also called shll sarl Src,Dest Dest = Dest &gt;&gt; Src Arithme&lt;c shrl Src,Dest Dest = Dest &gt;&gt; Src Logical xorl Src,Dest Dest = Dest ^ Src andl Src,Dest Dest = Dest &amp; Src Src,Dest Dest = Dest | Src orl Watch out for argument order! (especially subl)   No disMncMon between signed and unsigned int (why?)   x86 University of Washington Some ArithmeMc OperaMons   One Operand (Unary) InstrucMons incl Dest Dest = Dest + 1 decl Dest Dest = Dest - 1 negl Dest Dest = -Dest notl Dest Dest = ~Dest See textbook secMon...
View Full Document

## This document was uploaded on 04/04/2014.

Ask a homework question - tutors are online