CS 61C (Fall 2007) |
Quiz 10Two questions, submit as "quiz10". Due 2:45pm before lecture 9/21/2007. |
gcd (a, b) = a if b == 0, otherwise gcd (b, a%b)
Consider the following assembly language code, part of an implementation of this algorithm.
gcd: ... # push some information onto the stack bnez $a1,recursive_case # if b == 0 ... move $v0,$a0 # gcd = a j return recursive_case: rem $t0,$a0,$a1 # $t0 = a%b move $a0,$a1 # gcd = gcd (b, a%b) move $a1,$t0 jal gcd return: ... # pop the stack and return