It seems that my understanding of MIPS fails me.
What I need to do is create a program that reverses a string input from terminal, using a stack, but without using $sp. Is there anyone here that knows MIPS?
Register usage
t0 - theString address start
t1 - stack address start
t2 - temp for retrieved character
t3 - counter for t0
t4 - counter for stack
t5 - newline
t6 - Length
.data
theString: .space 42
newLine: .asciiz "\n"
stack: .space 42
.globl main
.text
main:
li $v0, 8 # Set to read string
la $a0, theString
li $a1, 42 # Set size of string
syscall # Read string from terminal
la $t0, theString # Prepare t0 with theString
la $t1, stack # Prepare t1 with stack
la $t5, newLine
addi $t3, $t0, 0
addi $t4, $t1, 42
j push
push:
addi $t3, $t3, 1
addi $t4, $t4, -1
lb $t2, ($t3)
beq $t2, $t5, epush
sb $t2, ($t4)
j push
epush:
sub $t6, $t3, $t0
addi $t6, $t6, -1
addi $t3, $t0, 0
addi $t4, $t1, 0
j pop
pop:
addi $t3, $t3, 1
addi $t4, $t4, 1
lb $t2, ($t4)
beq $t2, $t5, epop
sb $t2, ($t3)
j pop
epop:
addi $t3, $t3, 1
sb $t5, ($t3)
li $v0, 4 # Set to print string
la $a0, theString # Set var to syscall output register
syscall # Print string
li $v0, 10 # Set to end program
syscall # End Program
For example, this just gives an infinite loop. (Sorry for lack of comments, I'm just tearing my hair out here)
Now, I think the problem is somewhere related to the newline character, but I don't know where?