- #1
missinglink
- 1
- 0
I am trying to teach mips to my self and wrote a fairly simple program and it isn't working and found out that the strings I declared in .data are somehow affecting one of my pointers.
Here is the code:
#Write a program that allows the user to enter 5 ints and store these ints in an array and display them in reverse order
.data
msg: .asciiz "Enter your number: "
msg1: .asciiz "Here are your numbers: "
msg2: .asciiz " "
array: .data 20
.text
main:
la $s0, array
add $t0, $s0, $zero
li $t1, 0
li $t2, 5
loop:
li $v0, 4
la $a0,msg
syscall
li $v0, 5
syscall
add $t2, $v0, $zero
sw $t2, 0($t0) # This is the line causing errors
addi $t0, $t0, 4
addi $t1, $t1, 1
slt $t3, $t1, $t2
bne $t3, $zero, loop
li $v0, 4
la $a0, msg1
syscall
li $t5, 0
loop1:
add $t0, $t0, -4
lw $t4, 0($t0)
li $v0, 4
add $a0, $t4, $zero
syscall
li $v0, 4
la $a0, msg2
syscall
addi $t1, $t1, -1
slt $t2, $t5, $t1
bne $t2, $zero, loop1
li $v0, 10
syscall
Can anyone help please?
Here is the code:
#Write a program that allows the user to enter 5 ints and store these ints in an array and display them in reverse order
.data
msg: .asciiz "Enter your number: "
msg1: .asciiz "Here are your numbers: "
msg2: .asciiz " "
array: .data 20
.text
main:
la $s0, array
add $t0, $s0, $zero
li $t1, 0
li $t2, 5
loop:
li $v0, 4
la $a0,msg
syscall
li $v0, 5
syscall
add $t2, $v0, $zero
sw $t2, 0($t0) # This is the line causing errors
addi $t0, $t0, 4
addi $t1, $t1, 1
slt $t3, $t1, $t2
bne $t3, $zero, loop
li $v0, 4
la $a0, msg1
syscall
li $t5, 0
loop1:
add $t0, $t0, -4
lw $t4, 0($t0)
li $v0, 4
add $a0, $t4, $zero
syscall
li $v0, 4
la $a0, msg2
syscall
addi $t1, $t1, -1
slt $t2, $t5, $t1
bne $t2, $zero, loop1
li $v0, 10
syscall
Can anyone help please?