4edxeaxeax imull ecxeax order from c code some

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cx leal (%edx,%edx,2),%edx sall $4,%edx addl 16(%ebp),%ecx leal 4(%edx,%eax),%eax imull %ecx,%eax Offset • • • 16 z 12 y 8 x 4 Rtn adr 0 Old %ebp # # # # # # # # eax edx ecx edx edx ecx eax eax x86 = = = = = = = = x y x+y (t1) y + 2*y = 3*y 48*y (t4) z+t1 (t2) 4+t4+x (t5) t5*t2 (rval) Stack %ebp University of Washington ObservaMons about arith   InstrucIons in different int arith (int x, int y, int z) { int t1 = x+y; int t2 = z+t1; int t3 = x+4; int t4 = y * 48; int t5 = t3 + t4; int rval = t2 * t5; return rval; } movl 8(%ebp),%eax movl 12(%ebp),%edx leal (%edx,%eax),%ecx leal (%edx,%edx,2),%edx sall $4,%edx addl 16(%ebp),%ecx leal 4(%edx,%eax),%eax imull %ecx,%eax order from C code   Some expressions require mulIple instrucIons   Some instrucIons cover mulIple expressions   Get exact same code if we compile (x+y+z)*(x+4+48*y) # # # # # # # # eax edx ecx edx edx ecx eax eax x86 = = = = = = = = x y x+y (t1) y + 2*y = 3*y 48*y (t4) z+t1 (t2) 4+t4+x (t5) t5*t2 (rval) University of Washington Another Example int logical(int x, int y) { int t1 = x^y; int t2 = t1 >> 17; int mask = (1<<13) - 7; int rval = t2 & mask; return rval; } movl xorl sarl andl 8(%ebp),%eax 12(%ebp),%eax $17,%eax $8185,%eax # # # # eax eax eax eax logical: pushl %ebp movl %esp,%ebp movl xorl sarl andl Set Up 8(%ebp),%eax 12(%ebp),%eax $17,%eax $8185,%eax movl %ebp,%esp popl %ebp ret = = = = x x^y t1>>17 t2 & 8185 Offset Finish • • • 12 8 x Rtn adr 0 Old %ebp Stack y 4 x86 Body %ebp University of Washington Another Example int logical(int x, int y) { int t1 = x^y; int t2 = t1 >> 17; int mask = (1<<13) - 7; int rval = t2 & mask; return rval; } movl xorl sarl andl 8(%ebp),%eax 12(%ebp),%eax $17,%eax $8185,%eax logical: pushl %ebp movl %esp,%ebp movl xorl sarl andl 8(%ebp),%eax 12(%ebp),%eax $17,%eax $8185,%eax movl %ebp,%esp popl %ebp ret eax eax eax eax x86 = = = = x x^y (t1) t1>>17 (t2) t2 & 8185 Set Up Body Finish University of Washington Another Example int logical(int x, int y) { int t1 = x^y; int t2 = t1 >> 17; int mask = (1<<13) - 7; int rval = t2 & mask; return rval; } movl xorl sarl andl 8(%ebp),%eax 12(%ebp),%eax $17,%eax $8185,%eax logical: pushl %ebp movl %esp,%ebp movl xorl sarl andl 8(%ebp),%eax 12(%ebp),%eax $17,%eax $8185,%eax movl %ebp,%esp popl %ebp ret eax eax eax eax x86 = = = = x x^y (t1) t1&gt...
View Full Document

Ask a homework question - tutors are online