When turning in a homework problem, mark it with the exercise number shown in bold here. These will be the reference numbers I use in reporting back your standing on the homework.
2.49 on pages 153-154. This problem involves two different classifications of memory accesses. One concerns what is moving between the memory and processor: an instruction or a data value. The other concerns the direction of movement: from memory to the processor (a read) or from processor to memory (a write). Note that this exercise contains a typo in at least some printings of the textbook: Figure 2.48 is on page 146, not 141. Moreover, the problem statement says to use "the instruction mix information for ... the program SPEC200int." But in fact, SPEC2000int isn't a single program; it is a name for the mix of five integer programs included in SPEC2000. The bottom line for this: use the numbers from the integer column of Figure 2.48 on page 146.
2.x1: Consider the following MIPS procedure:
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 $ra
Assume $a0
and $a1
are used for arguments to
the procedure, which are nonnegative integers k and n,
respectively. Assume that $v0
is used for the
procedure's result value. Assume that all the numerical values stay
small enough that they do not overflow the size of the registers.
Write a simple mathematical formula expressing the result value in terms of k and n and briefly justify your answer.
Write an alternate version of the procedure 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. Your version should produce the same result as the original for any values of k and n that are greater than or equal to zero and small enough that no overflow results.
2.x2: Write a MIPS assembly language procedure named
whence
, such that after calling the procedure with the
instruction
jal whence
the procedure will return (to the next instruction after the
jal whence
) with the $v0
register
containing the address in memory where the
jal whence
instruction occurs.
Instructor: Max Hailperin