#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Posts
    3
    Rep 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?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Posts
    3
    Rep 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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Posts
    3
    Rep 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.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    Help me please.


    Hi guys I have an assingment with the MIPS, I really need someone to help me create the programs.

    They are very easy in JAVA but i got block with MIPS,

    please contact,
    kik josuebenpag

    MIPS HELP.


    Thank YOU GUYS...

IMN logo majestic logo threadwatch logo seochat tools logo