开发者

Trouble with assembly language homework

开发者 https://www.devze.com 2023-02-09 11:28 出处:网络
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.

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
    s开发者_StackOverflow中文版yscall
    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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消