cs313-2006-t2-problemset3 - CPSC 313 06W Term 2 Problem Set...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CPSC 313 06W Term 2 Problem Set #3 Due: Sunday, February 4, 2007 at 11:59 PM (thirteen-hour grace period) 1. Write in C a function int gcd(int x, int y); that returns the greatest common divisor of its two arguments. You may assume that they are both positive. Your function should compute the gcd using subtraction only. The algorithm is: if x == y, gcd(x, y) = x if x > y gcd(x, y) = gcd(x - y, y) if x < y gcd(x, y) = gcd(x, y - x) Write four versions of the algorithm: a recursive version a version that uses a for loop a version that uses a while loop a version that uses a do . . . while loop Compile each version with gcc -S -O2. (a) Turn in (on paper) all 4 versions of your .c files and their corresponding, gcc generated, .s files. (b) Describe the differences in the generated code of the four versions. Dont worry about trivial syntactic differences (like one version chooses register %ebx to hold some value while another version chooses a different register. You should look for differences that matter (semantic differences) such as: i. Differences in the number of registers used inside the loop ii. Differences in the number of branch instructions inside the loopii....
View Full Document

This note was uploaded on 10/09/2011 for the course CPSC 344 taught by Professor Karen during the Fall '10 term at The University of British Columbia.

Page1 / 3

cs313-2006-t2-problemset3 - CPSC 313 06W Term 2 Problem Set...

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

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