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

750% 50P%e This (now familiar) MPS SPIM program includes a subroutine called nya

ID: 3605179 • Letter: 7

Question


750% 50P%e This (now familiar) MPS SPIM program includes a subroutine called nyadd that performs xay+z;. In the space below, replace the nyadd subroutine with one named han that will compute x-ham(y,2)1, the Hamming Distance between y and t. Hamming Distance is defined as the number of bits that differ, and the following C code gives a simple algorithrm to compute it. This uses a liattle population of is m the XOR of the two numbers, ta & (ta-1) removes the least sig af ant l bit om the value of te trick credited to Brian Kem ghan an extern int x, y.i void o escn e ete to count th e han(void) int to yz int 11 -e; while (re) ( x-t Addition routiner globl eyadd ryadd: sea, y Ln St8,

Explanation / Answer

ham():

addiu $sp,$sp,-32

sw $fp,28($sp)

move $fp,$sp

lui $2,%hi(y)

lw $3,%lo(y)($2)

lui $2,%hi(z)

lw $2,%lo(z)($2)

nop

xor $2,$3,$2

sw $2,8($fp)

sw $0,12($fp)

lw $2,8($fp)

nop

beq $2,$0,$L2

nop

lw $2,12($fp)

nop

addiu $2,$2,1

sw $2,12($fp)

lw $2,8($fp)

nop

addiu $2,$2,-1

sw $2,16($fp)

lw $3,8($fp)

lw $2,16($fp)

nop

and $2,$3,$2

sw $2,8($fp)

b $L3

nop

lui $2,%hi(x)

lw $3,12($fp)

nop

sw $3,%lo(x)($2)

nop

move $sp,$fp

lw $fp,28($sp)

addiu $sp,$sp,32

j $31

nop

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote