Hello,
This is an assignment for my assembly class. What I am trying to do is take a string and reverse it. I'm using the stack to reverse the string.
I'm starting to get confused with the registers and the stack, and the general flow of the program. Also, how should I go about printing the reversed string to console? Pop an item off the stack and print it?
Any tips or suggestions would be greatly appreciated.
Edit: Not sure if It matters, but I'm using QtSpim simulator.
Edit 2: I've updated post with my latest code
I get this error now
Can't expand stack segment by 8 bytes to 524288 bytes.
Use -lstack#with# > 524288
Is this error happening because I'm trying to add too much to the stack?
Code:
This is an assignment for my assembly class. What I am trying to do is take a string and reverse it. I'm using the stack to reverse the string.
I'm starting to get confused with the registers and the stack, and the general flow of the program. Also, how should I go about printing the reversed string to console? Pop an item off the stack and print it?
Any tips or suggestions would be greatly appreciated.
Edit: Not sure if It matters, but I'm using QtSpim simulator.
Edit 2: I've updated post with my latest code
I get this error now
Can't expand stack segment by 8 bytes to 524288 bytes.
Use -lstack#with# > 524288
Is this error happening because I'm trying to add too much to the stack?
Code:
Code:
#Program 1 - Takes a string and reverses the string
#
#
# Cosc 300
.data
prompt: .asciiz " Given String is = "
str: .asciiz " aaaaBBBBccccDDDD "
ans: .asciiz " The String reversed is= "
.text
.globl main
main:
la $a0, prompt
li $v0, 4
syscall
la $a0, str
li $v0, 4
syscall
la $a0, ans
li $v0, 4
syscall
la $t1, str
li $t2, 0
Loop:
lb $t0, 0($t1)
beqz $t0, next
addi $sp, $sp, -4
sw $t0, 0($sp)
j Loop
next:
lw $t0, 0($sp)
beqz $t0, End
addi $sp, $sp, 4
li $v0, 4
move $a0, $t0
syscall
j next
End:
li $v0, 10
syscall