Question: This (now familiar) MIPS/SPIM program includes a subroutine called myadd that performs x=y+z;. In the space below, replace the myadd subroutine with one named ham

This (now familiar) MIPS/SPIM program includes a subroutine called myadd that performs x=y+z;. In the space below, replace the myadd subroutine with one named ham that will compute x=ham(y,z);, the Hamming Distance between y and z. Hamming Distance is defined as the number of bits that differ, and the following C code gives a simple algorithm to compute it. This uses a little trick credited to Brian Kernighan (and described here) to count the "population" of 1s in the XOR of the two numbers; t0 & (t0 - 1) removes the least-significant 1 bit from the value of t0.

extern int x, y, z; void ham(void) { int t0 = y ^ z; int t1 = 0; while (t0) { t1 = t1 + 1; t2 = t0 - 1; t0 = t0 & t2; } x = t1; } 

This (now familiar) MIPS/SPIM program includes a subroutine called myadd that performs

50% 50% This (now the Hamming Distance between y and z. Hamming Distance is defined as the number of bits that differ, and the following C code gives a simple algorithm to compute it. This uses a little trick credited to Brian Kernighan extern int x, y, z; void ham(void) liar) MIPS/SPIM includes a subroutine called myadd that performs x-y+z;. In the space below, replace the myadd subroutine with one named ham that will compute x-ham(y,z)i ) to count the "population" of Is in the XOR of the two numbers; to & (to - 1) removes the least-significant 1 bit from the value of to int to yzi int t1 = 0; while (to) tl tl+1 t2-to 1; x = t1; # Addition routine: #x-y+z text globl myadd myadd: la $t0, y #10-y la $t1, z lw $t1, 0($t1) la $to,x #x=t2 r a return 50% 50% This (now the Hamming Distance between y and z. Hamming Distance is defined as the number of bits that differ, and the following C code gives a simple algorithm to compute it. This uses a little trick credited to Brian Kernighan extern int x, y, z; void ham(void) liar) MIPS/SPIM includes a subroutine called myadd that performs x-y+z;. In the space below, replace the myadd subroutine with one named ham that will compute x-ham(y,z)i ) to count the "population" of Is in the XOR of the two numbers; to & (to - 1) removes the least-significant 1 bit from the value of to int to yzi int t1 = 0; while (to) tl tl+1 t2-to 1; x = t1; # Addition routine: #x-y+z text globl myadd myadd: la $t0, y #10-y la $t1, z lw $t1, 0($t1) la $to,x #x=t2 r a return

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!