question on mips code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gdarian216
    New Member
    • Oct 2006
    • 57

    question on mips code

    the following program is trying to copy words from the address in register $a0 to the address in register $a1, counting the number of words copied in register $v0. It will then stop copying when it finds a word equal to 0. i wasnt tring to preserve the contents of register $v1,$a0,$a1. the terminating word should be copied but not counted.

    this is what i have so far can anyone show me the buggs

    Code:
            addi $v0, $zero, 0          #initialize count
    loop: lw    $v1, 0($a0)             #read next word from source
            sw   $v1, 0($a1)             #write to destination
            addi $a0, $a0, 4            #advance pointer to next source
            addi $a1, $a1, 4            #advance pointer to next destination
            beq  $v1, $zero, loop     #loop if word copied != zero
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Originally posted by gdarian216
    this is what i have so far can anyone show me the buggs
    What makes you think it is buggy? What behaviour do you get, and how does this differ from what you expect?

    The only obvious error I see is that you never do anything with $v0 so you do not record the number of words copied.

    Comment

    • gdarian216
      New Member
      • Oct 2006
      • 57

      #3
      i wasn't sure Is there a simulator that I can test out my code because it was done in my head and when i handed it in my teacher said it had some bugs in it but didn't tell me where

      Comment

      • kaioshin00
        New Member
        • Nov 2006
        • 46

        #4
        Originally posted by gdarian216
        i wasn't sure Is there a simulator that I can test out my code because it was done in my head and when i handed it in my teacher said it had some bugs in it but didn't tell me where
        There is a simulator called PC Spim

        It's available here

        Comment

        • kaioshin00
          New Member
          • Nov 2006
          • 46

          #5
          Also ..

          Code:
          beq  $v1, $zero, loop     #loop if word copied != zero
          Shouldn't that be

          Code:
          bne  $v1, $zero, loop     #loop if word copied != zero
          ?

          Comment

          Working...