Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following instruction sequence interchanges (i.e. swaps) thecontents of regi

ID: 3614169 • Letter: T

Question

The following instruction sequence interchanges (i.e. swaps) thecontents of registers $v0 and $v1:

xor        $1,$v0,$v1

xor        $v0,$v0,$1

xor        $v1,$v1,$1

Show the implementation of a synthetic instruction that wouldhave the same effect and that only involves load and storeinstructions in conjunction with the stack. Your solutionshould not modify any registers other than the intended resultregister(s), should leave $sp with the same value as it had beforethe synthetic instruction and should not involve any type of branchor jump instruction.

Explanation / Answer

addi $sp, $sp -8 (makes room on stack) sw $v1, 0($sp) puts v1 on top of the stack sw $v0 , 4($sp) places v0 under v1 on stack lw $v1, 4($sp)   loads v1 move $v1, $v0   places v0 in v1 lw $v0, 0($sp)    loads v0 move $v1, $v0 places v0 in v1 addi $sp, $sp, 8 replaces free space back on stack forreuse