Question

write an assembly program which computes the hamming distance between the values in R0 and R1...

write an assembly program which computes the hamming distance between the values in R0 and R1 and returns the result in R2

Homework Answers

Answer #1

So I will provide the c++ code of hamming code after I will convert it into assembly language

If You have Any Query Regarding this please ask in comment section I will be there to solve all your query in comment section immediately hope you will like it


  
// Function to calculate hamming distance 

int hammingDistance(int n1, int n2) 
{ 

    int x = n1 ^ n2; 

    int setBits = 0; 

  

    while (x > 0) { 

        setBits += x & 1; 

        x >>= 1; 

    } 

hammingDistance:
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-20], edi
mov DWORD PTR [rbp-24], esi
mov eax, DWORD PTR [rbp-20]
xor eax, DWORD PTR [rbp-24]
mov DWORD PTR [rbp-4], eax
mov DWORD PTR [rbp-8], 0
jmp .L2
.L3:
mov eax, DWORD PTR [rbp-4]
and eax, 1
add DWORD PTR [rbp-8], eax
sar DWORD PTR [rbp-4]
.L2:
cmp DWORD PTR [rbp-4], 0
jg .L3
mov eax, DWORD PTR [rbp-8]
pop rbp
ret

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a .asm program that computes the Nth Fibonacci number. N will be provided in R0...
Write a .asm program that computes the Nth Fibonacci number. N will be provided in R0 and the output should be in R1
Write a Hack Assembly Language program to calculate the quotient from a division operation. The values...
Write a Hack Assembly Language program to calculate the quotient from a division operation. The values of dividend a and divisor b are stored in RAM[0] (R0) and RAM[1] (R1), respectively. The dividend a is a non-negative integer, and the divisor b is a positive integer. Store the quotient in RAM[2] (R2). Ignore the remainder. Example: if you are given two numbers 15 and 4 as dividend a (R0) and divisor b (R1), respectively, the answer will be 3 stored...
Write a simple ARM assembly language program that finds the mean (as an integer) of all...
Write a simple ARM assembly language program that finds the mean (as an integer) of all values of an integer array. When your program starts, you should assume that r0 contains the address of the array and r1 contains the number of integers in the array. When you program finishes, the mean should be stored in r2. You may use other registers as stack registers.
Modify this Mult.asm program to 1) ensure that the contents of R0 and R1 are not...
Modify this Mult.asm program to 1) ensure that the contents of R0 and R1 are not modified, and 2) allow for any combination of positive and negative operands (i.e. either of R0 and R1 can be positive or negative) @R2 M=0 // set r2 = to 0 @R0 D=M @count M=D // count = to r's (LOOP) @count D=M // set d equal to count @END D;JEQ // if count = 0, go to the end @R1 D=M // D=R1...
Write an assembly program to count the binary ones in register R1.   
Write an assembly program to count the binary ones in register R1.   
Write a complete assembly language program that computes in EAX the value of the expression x...
Write a complete assembly language program that computes in EAX the value of the expression x − 2y + 4z for doublewords in memory at x, y, and z. Choose the current month (1–12), day (1–31), and year (all four digits) for the values of x, y, and z.
Write an ARM assembly language program that counts the number of 1’s for any value in...
Write an ARM assembly language program that counts the number of 1’s for any value in R0. The program must assemble/compile in KEIL and must be able to run in the KEIL simulator. Generally, R0 may contain any value, but for purpose of this exercise, you may move 0x2345ABCD into R0. The number in R0 does not need be preserved. You may use any other registers as you need. The result, total count of 1’s in R0, should be in...
Write a program in microassembly to check if a number in register r2 is a perfect...
Write a program in microassembly to check if a number in register r2 is a perfect square.Save the Boolean result in register, r0.
A) write a program the computes nx and store the result into y You can use...
A) write a program the computes nx and store the result into y You can use y = Math.pow( Mantissa, exponent) Requirements: Besides main() your program must have one method with two parameters, one double and one int n and x are positive numbers read from the keyboard if the user makes an entry that does not meet this criteria, the user must be given to opportunity retry the entry the user must be able to quit prior to entering...
Write a piece of assembly code in SimpleRisc to find out if a number is a...
Write a piece of assembly code in SimpleRisc to find out if a number is a Factorian number or Dudeney number. Save 1 in r1 if it is a Factorian number; otherwise, save 0. Save 1 in r2 if it is a Dudeney number; otherwise, save 0. You have to write a single program to test both these conditions.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT