1

I thought I correctly implemented a while loop, but why am I not getting any output?

My book isn't that great of a help, and I haven't been able to find a resource online.

##### The Data Segment #########

.data
strFirstNumber:     .asciiz  "Enter the first number (0-63): "
strSecondNumber:    .asciiz  "Enter the second number (0-63): "
strError:           .asciiz  "That number is not in the 0-63 range.\n\n"

#### The Text Segment ##########

.text
.globl main

main:
    li $t2, 0
#First Number
    li $10, 64
    li $v0, 4
    la $a0, strFirstNumber
    syscall
    li $v0, 5
    syscall
    blez $v0, in_error
    bgeu $v0, $10, in_error
    j DoneIf

in_error:
    li $v0, 4
    la $a0, strError
    syscall
    li $v0, 4
    la $a0, strFirstNumber
    syscall
    li $v0, 5
    syscall
    bltz $v0, in_error
    bgeu $v0, $10, in_error

DoneIf:
    move $t0, $v0

#Second Number
    li $v0, 4
    la $a0, strSecondNumber
    syscall
    li $v0, 5
    syscall
    bltz $v0, in_error2
    bgeu $v0, $10, in_error2
    j DoneIf2

in_error2:
    li $v0, 4
    la $a0, strError
    syscall
    li $v0, 4
    la $a0, strSecondNumber
    syscall
    li $v0, 5
    syscall
    blez $v0, in_error2
    bgeu $v0, $10, in_error2

DoneIf2:
    move $t1, $v0

Loop:
    beq    $t2, $t0, Exit
    add    $t3, $t1, $t1
    add    $t2, $t2, 1

    j    Loop        # go to Loop

Exit:
    li $v0, 1
    add    $a0, $0, $t3
    syscall

    jr    $31
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
bdmflyer
  • 145
  • 11
  • You might want to mention what the specific problem is - does the code actually run ? Do you get the expected prompts ? Does it accept input ? What happens next ? What did you try in order to debug it ? – Paul R Feb 06 '11 at 20:54
  • Thanks. The code runs, and I can input the first and second number. But I can't get it to display the outcome. It doesn't display anything after the second number is inputted. The idea of the code is to do a while loop to mimic multiplication. I've tried single-stepping through it, but I can't figure out what I'm doing wrong. – bdmflyer Feb 06 '11 at 21:00
  • When single-stepping, do you make it to the loop? What are the values of `$t0` through `$t3` when you get there? Do you ever make it to `j Loop`? What are the values of the registers when you get there? – Karl Bielefeldt Feb 06 '11 at 21:18

2 Answers2

1

It's nearly impossible to say what's wrong:

  1. we don't know what's happen in syscalls.
  2. you are using $t registers to store value. This is bad because MIPS define them as scratch regiters. Use $s0 to $s7 instead
  3. we don't know your target. Is this real HW or emulator ?
  4. we don't know if the code complete

BTW, if you correctly entered both numbers, your code must run into the loop. Again, given that syscalls probably trashed registers, it may run for a ... long ... time.

Try to change register allocation first, then remove the loop that does not change the result computed into $t3. And possibly check that your syscall to print work correctly.

Laurent G
  • 2,994
  • 1
  • 18
  • 10
0

It is because you haven't described in the program what process happens in 'syscall' There seems to be no real output result.