Lecture9

Lecture9 - Assembly Programming Abhishek Bhattacharjee...

This preview shows pages 1–8. Sign up to view the full content.

Abhishek Bhattacharjee Topics s Introduction to Assembly Programming c x86 assembly Assembly Programming

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Rutgers University 2 Abhishek Bhattacharjee Using leal for Arithmetic 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 Body Set Up Finish
Rutgers University 3 Abhishek Bhattacharjee 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 # eax = x movl 12(%ebp),%edx # edx = y leal (%edx,%eax),%ecx # ecx = x+y (t1) leal (%edx,%edx,2),%edx # edx = 3*y sall \$4,%edx # edx = 48*y (t4) addl 16(%ebp),%ecx # ecx = z+t1 (t2) leal 4(%edx,%eax),%eax # eax = 4+t4+x (t5) imull %ecx,%eax # eax = t5*t2 (rval) y x Rtn adr Old % ebp %ebp 0 4 8 12 Offset Stack z 16

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Rutgers University 4 Abhishek Bhattacharjee 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; } # eax = x movl 8(%ebp),%eax # edx = y movl 12(%ebp),%edx # ecx = x+y (t1) leal (%edx,%eax),%ecx # edx = 3*y leal (%edx,%edx,2),%edx # edx = 48*y (t4) sall \$4,%edx # ecx = z+t1 (t2) addl 16(%ebp),%ecx # eax = 4+t4+x (t5) leal 4(%edx,%eax),%eax # eax = t5*t2 (rval) imull %ecx,%eax
Rutgers University 5 Abhishek Bhattacharjee 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; } logical: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax xorl 12(%ebp),%eax sarl \$17,%eax andl \$8185,%eax movl %ebp,%esp popl %ebp ret Body Set Up Finish movl 8(%ebp),%eax eax = x xorl 12(%ebp),%eax eax = x^y (t1) sarl \$17,%eax eax = t1>>17 (t2) andl \$8185,%eax 2 13 = 8192, 2 13 – 7 = 8185

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Rutgers University Abhishek Bhattacharjee 6 Condition Codes Single Bit Registers CF Carry Flag SF Sign Flag ZF Zero Flag OF Overflow Flag Can be set either implicitly or explicitly . s Implicitly by almost all logic and arithmetic operations s Explicitly by specific comparison operations Not Set by leal instruction s Intended for use in address computation only
Rutgers University Abhishek Bhattacharjee 7 Condition Codes Implicitly Set By Arithmetic Operations addl Src , Dest C analog: t = a + b s CF set if carry out from most significant bit

This preview has intentionally blurred sections. Sign up to view the full version.

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

This document was uploaded on 10/31/2011 for the course 198 211 at Rutgers.

Page1 / 26

Lecture9 - Assembly Programming Abhishek Bhattacharjee...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online