CAS CS 210 -Computer Systems Fall 2012 PROBLEM SET 2 (P

CAS CS 210 -Computer Systems Fall 2012 PROBLEM SET 2 (PS2) (PROGRAM REPRESENTAITON) OUT: TUESDAY OCT 8 DUE: TUESDAY OCT 23 1:30 PM NO LATE SUBMISSIONS WILL BE ACCEPTED To be completed individually. For all questions show your work in obtaining the final answers. Page 1 of 7
1 Problem 1: 6 Points Match each of the assembler routines on the left with the equivalent C function on the right. foo1:pushl %ebp movl %esp%ebp movl 8(%ebp)%eax sall $4%eax subl 8(%ebp)%eax movl %ebp%esp popl %ebp ret foo2:pushl %ebp movl %esp%ebp movl 8(%ebp)%eax testl %eax%eax jge .L4 addl $15%eax .L4: sarl $4%eax movl %ebp%esp popl %ebp ret foo3:pushl %ebp movl %esp%ebp movl 8(%ebp)%eax shrl $31%eax movl %ebp%esp popl %ebp ret int choice1(int x) { return (x > 31); }Fill in your answers here: foo1 corresponds to choice . foo2 corresponds to choice . foo3 corresponds to choice . Page 2 of 7
2 Problem 2: 10 Points Consider the following assembly representation of a function foo containing a for loop: foo: pushl %ebp movl %esp%ebp pushl %ebx movl 8(%ebp)%ebx leal 2(%ebx)%edx xorl %ecx%ecx cmpl %ebx%ecx jge .L4 .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: int foo(int a) f int i; int result = _____________; for( ________; ________; i++ ) f __________________; __________________; greturn result; g Page 3 of 7
3 Problem 3: 20 Points Consider the following C code 1 # i n c l u d e 23 void my c a l l e e ( i n t s i n t e c h a r buf ) 4 f 5 f o r ( ; s


You can leave a response, or trackback from your own site.
error: Content is protected !!