Solution to CSE - Sample Final Exam - AY1011-S1

Solution to CSE - Sample Final Exam - AY1011-S1 - Computer...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE – Sample Final Exam AY1011-S1– Page 1/5 Computer Systems Engineering AY1011–S1 (Open book, no computer, and no PDA) Sample Final Examination –Duration: 120 minutes Q1. (10 pts) Consider the following C functions and assembly code: Which of the functions compiled into the assembly code shown? Briefly explain your answer. Solution: fun3 The following sequence of instructions: movl 8(%ebp),%edx ; edx <- [ebp + 8] = ap movl 12(%ebp),%eax ; eax <- [ebp + 12] = bp movl %ebp,%esp ; esp <- ebp movl (%edx),%edx ; edx <- [ap] (= *ap) addl %edx,(%eax) ; [eax] <- [eax] + edx ( = *bp <- *bp + *ap) movl %edx,%eax ; eax <- edx (= *ap) Dereferences *ap and moves the value into %edx. Then it adds that value with the value in %eax (*bp)and stores it back into the location pointed to by %eax. Finally the code returns *ap by putting %edx into %eax. Q2. (20 pts) Consider the following assembly representation of a function test containing a for loop: test: pushl %ebp movl %esp,%ebp pushl %ebx movl 8(%ebp),%ebx leal 2(%ebx),%edx xorl %ecx,%ecx cmpl %ebx,%ecx jge .L4
Background image of page 1

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

View Full DocumentRight Arrow Icon
CSE – Sample Final Exam AY1011-S1– Page 2/5 .L6: leal 5(%ecx,%edx),%edx leal 3(%ecx),%eax imull %eax,%edx incl %ecx cmpl %ebx,%ecx jl .L6 .L4: movl %edx,%eax popl %ebx movl %ebp,%esp popl %ebp ret Fill in the blanks to provide the functionality of the loop:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/22/2011 for the course ECE 410 taught by Professor Staff during the Spring '08 term at University of Illinois, Urbana Champaign.

Page1 / 5

Solution to CSE - Sample Final Exam - AY1011-S1 - Computer...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online