View Single Post
Old Dec 4th, 2006, 8:52 PM   #31
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 333
Rep Power: 4 cwl157 is on a distinguished road
alright. One problem left it prints 1 for the hamming distance everytime. I think its because i don't quite understand how the printing stuff works so im printing the wrong register.
here is the code though:
.text

main:
	la $a0,prompt_in      #print prompt on terminal
	li $v0,4              #prints a string on the terminal
	syscall

	li $v0,5	      #reads in an integer
	syscall
	sw $v0,num1

	la $a0,prompt_ina      #print prompt on terminal
	li $v0,4               #prints a string on the terminal
	syscall

        li $v0,5	       #reads in an integer
	syscall
	sw $v0,num2

	lw $v0,num1		#set a
	lw $t0,num2		#set b

	xor $v1,$v0,$t0		# $v1 is c.  compare $v0 and $t0 and store in $v1

	move $s1, $zero		#s1 is the counter set to 0
	move $s2, $zero		#set hamming to 0
	li $s6,1		#set $s6 to 1
loop:
	and $s4,$v1,$s6		#s4 is d and c with d store in $s4	
	beq $s4, $s6,hamming	#set s5 equal to 1 if d equals 1
	srl $v1, $v1, $s6	#shift c right by 1
	addi $s1, $s1, 1	#i = i + 1 increment loop counter
	li $s7,32		#set $s7 to 32
	blt $s1,$s7,loop	#if loopCount <32 go to loop
	beq $s1,$s7,loop	#if loopCount == 32 go to loop
	#j loop			#goto loop
	
hamming:
	addi $s2, $s2, 1	#increment hamming

print:
	la $a0,prompt_out      #print prompt on terminal
	li $v0,4              #prints a string on the terminal
	syscall

	move $a0, $s2		# syscall 1 prints an integer
	li $v0, 1
	syscall

	li $v0,10              #exit program
	syscall



.data
prompt_in:    .asciiz "Enter first integer: "            # first integer
prompt_ina:    .asciiz "Enter second integer: "          #second integer
prompt_out:   .asciiz "The hamming distance is "
num1: .word 0
num2: .word 0
cwl157 is offline   Reply With Quote