dimanche 18 septembre 2016

How to compare values within registers in MIPS?

I am trying to create a function that prompts the user to enter a number between 3 and 30 and if the number is less than 3 it will display "your number is less than 3", and if the number is greater than 30 it will display "your number is greater than 30". This may be dumb but I am new to MIPS and I don't quite understand what I am doing wrong.

Thank you

.data
prompt: .asciiz "Enter your number (3-30):"
message: .asciiz "\n Your number is "
message2: .asciiz "\n Your number is less than 3"
message3: .asciiz "\n Your number is more than 30"
.text 
# Prompt the user to enter the number
li $v0, 4
la $a0, prompt
syscall

# Get the number 
li $v0, 5 #get an integer from the user
syscall

# Store the result in t0
move $t0, $v0

main: #syscall to end the program
    addi $t1, $zero, 0
    addi $t2, $zero, 3
    addi $t3, $zero, 30

    ble $t0, $t1, numberSmaller
    bge $t0, $t2, numberLarger

    li $v0, 10
    syscall

numberSmaller:
    li $v0, 4
    la $a0, message2
    syscall
numberLarger:
    li $v0, 4
    la $a0, message3
    syscall

Aucun commentaire:

Enregistrer un commentaire