Lecture 6

# T4 y 48 int t5 t3 t4 int rval t2 t5 return rval movl

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: 3.5.5 for more instrucMons: mull, cltd, idivl, divl   x86 University of Washington Using leal for ArithmeMc Expressions 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; } arith: pushl %ebp movl %esp,%ebp 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 movl %ebp,%esp popl %ebp ret x86 Set Up Body Finish University of Washington Understanding arith 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 Oﬀset • • • 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 Understanding arith 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 Oﬀset • • • 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 Understanding arith 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 Oﬀset • • • 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 Understanding arith 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),%e...
View Full Document

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

Ask a homework question - tutors are online