Computer Science > QUESTIONS & ANSWERS > Northwestern UniversityEECS 213 HOMEWORK 2 SOLUTION FALL 2020 (All)
EECS213, Fall 2015 HOMEWORK 2 SOLUTION Problem 1 (20 points) For each IA32 assembly code sequence below on the left, fill in the missing portion of corresponding C line on the right. Simplify th... e C code as much as possible. foo: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax sall $5,%eax subl 8(%ebp),%eax movl %ebp,%esp popl %ebp ret int foo(int x) { return 31*x; // (x<<5) x } foo: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax testl %eax,%eax jge .L4 addl $3,%eax .L4: sarl $2,%eax movl %ebp,%esp popl %ebp ret int foo(int x) { return x/4; // (x>=0 ? x:(x+3)) >> 2; } foo: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax shrl $16,%eax movl %ebp,%esp popl %ebp ret int foo(int x) { return (int) ((unsigned int)x >> 16); } foo: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax sall $4,%eax addl 8(%ebp),%eax addl %eax,%eax movl %ebp,%esp popl %ebp ret int foo(int x) { return 34*x; // 2*(x<<4 + x); } foo: pushl %ebp movl %esp,%ebp movl 8(%ebp),%edx movl 12(%ebp),%eax movl %ebp,%esp movl (%edx),%edx addl %edx,(%eax) movl %edx,%eax popl %ebp ret int foo(int *xp, int *yp) { int x = *xp; *yp += *xp; // or *yp += x; return x; } This study source was downloaded by 100000784424693 from CourseHero.com on 04-28-2021 01:53:06 GMT -05:00 https://www.coursehero.com/file/14225010/HW2sol/ his stu ed via y re | ourse urce wa Hero.co sha Problem 2 (20 points) Consider the following assembly representation of a function forloop containing a loop: forloop: pushl %ebp movl %esp, %ebp subl $16, %esp movl $1, 4(%ebp) movl $0, 8(%ebp) jmp .L2 .L3: movl 8(%ebp), %eax addl %eax, %eax addl $5, %eax addl %eax, 4(%ebp) addl $1, 8(%ebp) .L2: movl 8(%ebp), %eax cmpl 8(%ebp), %eax jl .L3 movl 4(%ebp), %eax leave ret Fill in the blanks to provide the functionality of the loop. Note that 8(%ebp) stores the argument a. intforloop ( inta) { inti; intresult =1; for (i = 0 ;i <a ;i ++ ){ result += ( 2 * i + 5 ); }re turnresult; } W hat is the size of stack frame in bytes (including %ebp and %esp)? 20 ... a ret address forloop %ebp result [Show More]
Last updated: 1 year ago
Preview 1 out of 8 pages
Connected school, study & course
About the document
Uploaded On
Apr 28, 2021
Number of pages
8
Written in
This document has been written for:
Uploaded
Apr 28, 2021
Downloads
0
Views
64
In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Browsegrades · High quality services·