.text
.globl main
main:
# input the string
# push each character onto the stack
# pop chars from stack back into the buffer
# print the reversed string
.data
str: .space 128 # character buffer
Here is the first secion of the program filled in. It merely reads in a line from the terminal in the usual way. To shortent the program, there is no user prompt.
# Reverse and output a user-supplied string
#
# Settings: Load delays OFF; Branch delays OFF,
# Trap file ON; Pseudoinstructions ON
#
# $t0 --- character pushed or popped
# $t1 --- index into string buffer str
.text
.globl main
main: #input the string
li $v0,8 # service code
la $a0,str # address of buffer
li $a1,128 # buffer length
syscall
# initialize the stack:
li $t0,_____ # push a null
____ $sp,$sp,4 # onto the stack
sw $t0,(___) # to signal its bottom
li $t1,0 # index of first char in str buffer
# push each character onto the stack
# pop chars from stack back into the buffer
# print the reversed string
.data
str: .space 128 # character buffer
Next the stack is initialized. Null is pushed onto the stack. Later on the stack will be popped until this null is encountered.