Hasan Butt
Hasan Butt

Reputation: 1

Can anyone tell what mistake i'm doing in this MIPS code?

   .data
array:  .space 10
prompt: .asciiz "Enter an integer (0 to quit) :"
text:   .asciiz "After sorting, the list of integers is:"
  .text
  .globl main
main:
  la $a1, array
read_numbers:
  # Rest of code omitted for brevity...
  beqz $v0, sort
  j read_numbers

sort:
  la $a1, $array

  li $v0, 4
  la $a0, text
  syscall

loop:
  lw $t0, 0($a1)
  addiu $a1, $a1, 4

  beqz $t0, done

  li $v0, 1
  move $a0, $t0
  syscall

  j loop

Upvotes: 0

Views: 30

Answers (1)

lostbard
lostbard

Reputation: 5220

Assuming that the code above is formatted correctly in the file rather than all on one line, and ignoring that you are missing code at

# Rest of code omitted for brevity

And ignoring that you haven't said what it is supposed to do, or what it does do ….

The first thing I see if that you are branching in main:

read_numbers: # Rest of code omitted for brevity...
  beqz $v0, sort 
  j read_numbers

But since you didn't set v0 to anything, it is set to whatever value it was set to before your code (and when I go to run it, non zero)

So, it never branched to the sort routine, and jumps to read_numbers and does an endless loop.

If it was in the 'sort', it will grab the first number from array, which is 0 (unless you had populated the array somehow), see that it was 0 and attempt to branch to 'done' which also isn't in your code.

Upvotes: 1

Related Questions