I am new at using MIPS and I try to calculate Hamming distance. However even the register $t3 has the correct XOR result, when I print it in decimal I get a wrong number.
word1: .word 0xffeff0ff
word2: .word 0x00000001
when I XOR these two words, the result is:
ffeff0fe
my question is how do I calculate it in decimal ?
Because I tried to print it in screen and I got -1052418 instead of the correct 26
Here is my complete code
.text
.globl __start
__start:
la $a1,word1
lw $t1,0($a1)
la $a1,word2
lw $t2,0($a1)
xor $t3,$t1,$t2
la $a0,answer
li $v0,4
syscall
move $a0,$t3
li $v0,1
syscall
la $a0,endl
li $v0,4
syscall
EXIT: li $v0,10
syscall
.data
word1: .word 0xffeff0ff
word2: .word 0x00000001
answer: .asciiz "Hamming distance is : "
endl: .asciiz "\n"
You are printing the xor of the two values instead of the number of bits which have different value. what you need to do to compute the hamming distance is to count that number, for example with this code:
This snippet assumes that your MIPS processor has delayed branching. If it is not the case, you have to move instruction marked with (*) after label skip. The nop can be removed if you don’t have delayed branching or if the next instruction does not have side effects.
This code should go instead of the line where you put
move $a0,$t3