SunQuest
           Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 10th, 2007, 10:51 PM
Fox5 Fox5 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 3 Fox5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 10 sec
Reputation Power: 0
Please help me debug my MIPS assembly? Presumebly a logical error...

Ok, this is an assignment for my computer organization class, and we were required to:
Read in an integer less than 4096
And then print out the first 12 bits and their values, so for instance, 100 would display as
0 0
1 0
2 1
3 0
4 0
5 1
6 1
7 0
8 0
9 0
10 0
11 0

Code:


                        #Sets $s0 (the loop counter) equal to 0

        li $s0, 0                                       #Set $s0 equal to 0

                        #Copies the user input from the temporary to $s1

        add $s1, $t0, $zero                             #Store $t0 in $s1

                        #This is the start of a loop that should go through the loop 12 times.
                        #On each iteration it should check if the current value is odd or even (divide by 2 and check for remainder).
                        #Then it should cut off the end digit and output a 1 if there was a remainder.

loop:   slt $t0, $s0, 12                                #$t0 = 1 if loop counter is less than 12
        bne $t0, 1, exit                                #Exit loop on the 12th iteration

                        #Load 2 into $t3 so it can be used for division. (no divide immediate command), then divide the number by 2.

        li $t3, 2  
        add $t1, $s1, $zero                             #Store $s1 in temp $t1
        div $t1, $t3                                    #Divide the integer by 2

                        #Load the remainder and see if it's greater than 0 (ie, there is a remainder).

        mfhi $t4                                        #Stores the remainder in $t4
        slt $t2, $zero, $t4                             #Store 1 in $t2 if there is a remainder
        sll $s1, $s1, 1                                 #Shifts the word right 1 bit


        li $v0, 1                                       #System call code for print_int
        add $a0, $s0, $zero                             #Load in current loop iteration
        syscall                                         #Print current loop iteration


        li $v0, 4                                       #System call for print_str
        la $a0, t                                       #Load in tab
        syscall                                         #Print the tab


        li $v0, 1                                       #System call for print_int
        beq $t2, 1, printOne                            #If there is a remainder, go print 1, else print 0


        li $a0, 0                                       #Load in the number 0
        j Print                                         #Print out the number

printOne:       li $a0, 1                               #Load in the number 1

Print:  syscall                                         #Print out the number

        li $v0, 4                                       #System call for print_str
        la $a0, n                                       #Load in the new line
        syscall                                         #Print the new line

        addi $s0, $s0, 1                                #Increment the loop counter
        j loop                                          #Jump to the top of the loop

exit:   li $v0, 10                                      #System call for exit
        syscall                                         #Exit


I left out some stuff at the beginning (prompting for user input, getting user input), but I'm pretty sure that's correct.
I'm not sure what's wrong with my code, but no matter what the input, I end up with 1 in the first bit, and 0's in all remaining bits. Anyone with a decent understanding of assembly code who can help me with this? At the very least, anyone know why the first loop iteration outputs a 1 and every subsequent iteration outputs a 0?

Reply With Quote
  #2  
Old April 11th, 2007, 10:28 AM
Fox5 Fox5 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 3 Fox5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 10 sec
Reputation Power: 0
Oh, just wanted to note, I am aware of the discrepency between the sll (shift left logical) command and the comment next to it, I wasn't sure if maybe I was messing up the endian of the spim simulator (manual mentions it takes on the same endianess of the machine it's running on and not native mips), but neither a sll or a srl outputs any different results.

Reply With Quote
  #3  
Old April 11th, 2007, 12:50 PM
Fox5 Fox5 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 3 Fox5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 10 sec
Reputation Power: 0
OMG, so many hours wasted over something so stupid.
The error was actually at the start of my program, I never stored the user input. Well, that explains why the output was always 1, it's because what was stored in the register at the time was a result of a slt. Wish I had gone over the states of the registers at the start rather than assuming it was some weird error.

Ok, well I guess no help necessary on this one guys.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Please help me debug my MIPS assembly? Presumebly a logical error...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway