- #1
Snoogx
- 22
- 0
I am writing a bigger program, but having trouble right now seeing where my mistake is on the output side of the code. The snippet of code below prints a message to the screen, takes the users input (which is supposed to be an integer), then is supposed to print it back out to the screen. The code seems to work fine but when it prints out the integer to the screen it's not correct. It gives me a different, longer number. Maybe someone can shed some light to my dilemma. Thanks.
The code in orange (after the #) is omitted because I'm working this as an array in my bigger program.
The code in orange (after the #) is omitted because I'm working this as an array in my bigger program.
PHP:
.data
set1: .space 32
msg2: .asciiz "please enter a value: "
.text
.globl main
main:
li $v0, 4 #load value for print_string
la $a0, msg2 #load address of msg2 into $a0
syscall #print msg2 to screen
li $v0, 5 #load value for read_int
syscall #read inputted value
move $a1, $v0 #move value into $a1
la $a0, set1 #load address of set1 into $a0
#move $t2, $s1
#sll $t2, $t2, 2
#add $t1, $t2, $a0
sw $a1, 0($a0) #store $a1 into first spot of $a0
li $v0, 1 #load value for print_int
la $a0, set1 #load address of set1
#move $t2, $s1
#sll $t2, $t2, 2
#add $t1, $t2, $a0
lw $a1, 0($a0) #load contents of $a0 with offset 0 into $a1
syscall #print $a1 to screen
li $v0, 10 #load value for exit
syscall #exit program