Computer Science  >  QUESTIONS & ANSWERS  >  Northwestern UniversityEECS 213 HOMEWORK 2 SOLUTION FALL 2020 (All)

Northwestern UniversityEECS 213 HOMEWORK 2 SOLUTION FALL 2020

Document Content and Description Below

EECS­213, 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. int​forloop​ (​ int​a) { ​ int​i; ​ int​result ​ =​1; ​ for​ (​i ​ =​​ 0​ ;​i ​ <​a​ ;​i​ ++​​ )​{ result ​ +=​​ (​ 2​ *​ i ​ +​​ 5​ ); }​re turn​result; } 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: 3 years ago

Preview 1 out of 8 pages

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)
Preview image of Northwestern UniversityEECS 213 HOMEWORK 2 SOLUTION FALL 2020 document

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Reviews( 0 )

$7.00

Buy Now

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Instant download

Can't find what you want? Try our AI powered Search

117
0

Document information


Connected school, study & course


About the document


Uploaded On

Apr 28, 2021

Number of pages

8

Written in

All

Seller


Profile illustration for d.occ
d.occ

Member since 4 years

234 Documents Sold

Reviews Received
30
8
4
1
7
Additional information

This document has been written for:

Uploaded

Apr 28, 2021

Downloads

 0

Views

 117

Document Keyword Tags


$7.00
What is Scholarfriends

Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.

We are here to help

We're available through e-mail, Twitter, and live chat.
 FAQ
 Questions? Leave a message!


Copyright © Scholarfriends · High quality services·