Assignment 3 Read the assembly code below


Rate this product

Assignment 3

Note: Make reasonable assumptions where necessary and clearly state them. Feel free to
discuss problems with classmates, but the only written material that you may consult while
writing your solutions are the textbook and lecture slides/videos. Solutions should be
uploaded as a single pdf file on Canvas. Show your solution steps so you receive partial
credit for incorrect answers and we know you have understood the material. Don’t just
show us the final answer.
1. Read the assembly code below; add comments to explain what each line of code is
doing; in one sentence, explain what this procedure is trying to accomplish. (15
sll $a0, $a0, 24
srl $a0, $a0, 24
add $v0, $a0, $zero
jr $ra
2. Read the assembly code below; add comments to explain what each of line of code is
doing; provide a simple equation to express the return value v0 as a function of input
arguments a0 and a1. (35 points)
blt $a1, $zero, loop2
beq $a1, $zero, proc-end
sll $a0, $a0, 1
addi $a1, $a1, -1
j loop1
beq $a1, $zero, proc-end
srl $a0, $a0, 1
addi $a1, $a1, 1
j loop2
add $v0, $a0, $zero
jr $ra
3. For the (pseudo) assembly code below, replace X, Y, P, and Q with the smallest set of
instructions to save/restore values on the stack and update the stack pointer. Assume
that procA and procB were written independently by two different programmers who
are following the MIPS guidelines for caller-saved and callee-saved registers. In other
words, the two programmers agree on the input arguments and return value of
procB, but they can’t see the code written by the other person. Be sure to read the
class notes first so you understand the MIPS guidelines for caller-saved and calleesaved registers. (50 points)
2018/10/7 CS/EE 3810 2/2
$s0 = …
$s1 = …
$s2 = …
$t0 = …
$t1 = …
$t2 = …
$a0 = …
$a1 = …
jal procB
… = $s1
… = $t0
… = $t1
… = $a0
jr $ra
… = $a0
… = $a1
$s2 = …
$t0 = …
jr $ra

Open chat
Need help?
Can we help you?