Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 4th, 2006, 8:52 PM   #31
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 327
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
Old Dec 4th, 2006, 8:57 PM   #32
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 327
Rep Power: 4 cwl157 is on a distinguished road
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?
cwl157 is offline   Reply With Quote
Old Dec 4th, 2006, 9:00 PM   #33
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 816
Rep Power: 4 The Dark is on a distinguished road
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:
When it jumps to hamming, there is nothing to make it jump back. It also goes through the hamming code when the loop finishes so it will always add 1
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?
The Dark is offline   Reply With Quote
Old Dec 4th, 2006, 9:02 PM   #34
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 816
Rep Power: 4 The Dark is on a distinguished road
Quote:
Originally Posted by cwl157 View Post
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?
before you check to see if you need to go around again, you could put
	move $a0, $s2		# syscall 1 prints an integer
	li $v0, 1
	syscall
The Dark is offline   Reply With Quote
Old Dec 4th, 2006, 9:06 PM   #35
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 327
Rep Power: 4 cwl157 is on a distinguished road
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.
cwl157 is offline   Reply With Quote
Old Dec 4th, 2006, 9:08 PM   #36
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 327
Rep Power: 4 cwl157 is on a distinguished road
it said 0 and then the hamming distance is 1 so yea i think its only going through the loop one time.
cwl157 is offline   Reply With Quote
Old Dec 4th, 2006, 9:12 PM   #37
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 327
Rep Power: 4 cwl157 is on a distinguished road
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?
cwl157 is offline   Reply With Quote
Old Dec 4th, 2006, 9:19 PM   #38
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 816
Rep Power: 4 The Dark is on a distinguished road
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 loop

This link seems to have a nice list of MIPS instructions.
The Dark is offline   Reply With Quote
Old Dec 4th, 2006, 9:36 PM   #39
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 327
Rep Power: 4 cwl157 is on a distinguished road
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.
cwl157 is offline   Reply With Quote
Old Dec 4th, 2006, 9:39 PM   #40
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 816
Rep Power: 4 The Dark is on a distinguished road
So what does your code look like now?
The Dark is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:21 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC