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

Write an assembly language function to determine the hamming distance (the numbe

ID: 3624083 • Letter: W

Question

Write an assembly language function to determine the hamming distance (the number of different bits) between two characters passed as a parameter. An implementation of Hamming distance in C programming language is copied below.

int returndistance(int x, int y)
{
unsigned dist=0, val= x^y;
// Count the number of set bits whil(val)
{
++dist;
val &=val-1;
}
return(dist);
}

The assembly language skeleton for the function is given as below

.global_returndistance
_returndistance:
Pushl %ebp
Movl %esp,%ebp

Movl 8(%ebp,%ebx
Movl 12(%ebp),%edx


//TODO: Write your code for finding hamming distance here


//put distance to be returned in eax
Movl %ebp,%esp
Popl %ebp
Ret


Thank you life saver!!!

Explanation / Answer

Dear, Here is the code for function .global_returndistance
_returndistance:
Pushl %ebp
Movl %esp,%ebp

Movl 8(%ebp,%ebx
Movl 12(%ebp),%edx
mov eax,$0 //t2 to store value of val
//Logic to find x^y Loop1: CMP $edx,$0              JE NEXT1              MUL $t2,ebx              DEC edx              JMP Loop1 NEXT1:             CMP $t2,$0             JE NEXT2             INC eax             DEC $t2             JMP Loop2 NEXT2:            
//put distance to be returned in eax
Movl %ebp,%esp
Popl %ebp
Ret


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