![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#31 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 343
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#32 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 343
Rep Power: 4
![]() |
and how do i even go about starting to debug it. Printing stuff takes like 3 lines. Like is there a way to print out what hamming distance is after every time through the loop?
|
|
|
|
|
|
#33 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 850
Rep Power: 4
![]() |
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: It might be easier to just jump around the hamming increment code if $s4 is equal to zero. Did you look at the google search for less than or equal to? |
|
|
|
|
|
#34 | |
|
Expert Programmer
Join Date: Jun 2005
Posts: 850
Rep Power: 4
![]() |
Quote:
move $a0, $s2 # syscall 1 prints an integer li $v0, 1 syscall |
|
|
|
|
|
|
#35 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 343
Rep Power: 4
![]() |
well the simulator im using has a single step option so i did that and didnt get much from it but what i did notice was it looked like it was only going through the loop once.
|
|
|
|
|
|
#36 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 343
Rep Power: 4
![]() |
it said 0 and then the hamming distance is 1 so yea i think its only going through the loop one time.
|
|
|
|
|
|
#37 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 343
Rep Power: 4
![]() |
i think i know the problem. when the hamming distance increases i have to have it branch to another part of the program to do that which is called hamming. So when it goes through that its out of the loop and then goes to print. Can i like somehow have the hamming being added under a label but then put that label still in the loop or maybe put the check and stuff under the hamming label?
|
|
|
|
|
|
#38 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 850
Rep Power: 4
![]() |
I'd do something like:
loop:
and $s4,$v1,$s6 #s4 is d and c with d store in $s4
beq $s4, 0, nohamming #Jumpt to nohamming if $s4 is zero
addi $s2, $s2, 1 #increment hamming
nohamming:
srl $v1, $v1, $s6 #shift c right by 1
addi $s1, $s1, 1 #i = i + 1 increment loop counter
ble $s1,32,loop #if loopCount <=32 go to loopThis link seems to have a nice list of MIPS instructions. |
|
|
|
|
|
#39 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 343
Rep Power: 4
![]() |
nope nevermind i was an idiot and was making the check twice. It seems to work thank you so very much for the help and simplifying the actual problem for me. When the problem was first explained it was dealing with arrays and adding things to them and looping through them and everything. I guess that made the most sense to me because of the java i've done that wouldn't have been that big of a deal in java but this is really different.
|
|
|
|
|
|
#40 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 850
Rep Power: 4
![]() |
So what does your code look like now?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Assembly Language for Intel-Based Computers | melbolt | Book Reviews | 0 | Aug 15th, 2006 12:04 AM |
| Language display in program | Prm753 | C++ | 3 | May 30th, 2006 5:45 PM |
| More languages? | UnKnown X | Coder's Corner Lounge | 27 | Dec 18th, 2005 3:06 PM |
| Does assembly language vary per machine? | Xero | Assembly | 9 | Jan 17th, 2005 11:34 AM |