loop: beq $a1, $zero, finish add $v0, $a0, $a0 add $a0, $v0, $a0 addi $a1, $a1, -1 j loop finish: add $v0, $a0, $zero jr $raAssume
$a1are used for arguments to the procedure, which are nonnegative integers k and n, respectively. Assume that
$v0is used for the procedure's result value. Write a simple mathematical formula expressing this result value in terms of k and n, and briefly explain how you reach this conclusion.
Also, write an alternate version of the program that only uses one branch or jump instruction each time through the loop, rather than both a branch and a jump each time. You may use additional branch or jump instructions, if you like, that are executed only once regardless of how many times the loop is taken.
whence, such that after calling the procedure with the instruction
jal whencethe procedure will return (to the next instruction after the
jal whence) with the
$v0register containing the address in memory where that
jal whenceinstruction occurs.
Instructor: Max Hailperin