Sha256: 1a25c844a139626bf1f6bddcbe331fa11a4577f094dbc202d51ec21d14d50011
Contents?: true
Size: 975 Bytes
Versions: 396
Compression:
Stored size: 975 Bytes
Contents
# Calculate the hamming distance of two strings # $a0 - pointer to string 1 # $a1 - pointer to string 2 # $v0 - output, integer form of binary string # $t0 - character of string 1 # $t1 - character of string 2 # $t2 - are the characters different? .globl hamming_distance hamming_distance: li $v0, 0 # Reset accumulator to 0. loop: lb $t0, 0($a0) # Load a character of string 1, beq $t0, $zero, end # if it is null then return. lb $t1, 0($a1) # Otherwise also load a character of string 2. sne $t2, $t0, $t1 # Determine if characters are different addu $v0, $v0, $t2 # and add the difference to accumulator. addi $a0, $a0, 1 # Finally, increment the pointer for string 1 addi $a1, $a1, 1 # and for string 2 j loop # and loop. end: jr $ra
Version data entries
396 entries across 396 versions & 1 rubygems