Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- input: .space 41
- blank: .asciiz "\n"
- .text
- .globl main
- main:
- #input the string
- li $v0,8 # service code
- la $a0,input # address of buffer
- li $a1,41 # buffer length
- syscall
- li $t0,0 # push null onto stack
- addi $s0,$s0,-4
- sw $t0,($s0) # this indicates the bottom of the stack
- li $t1,0 # where the first character of the string is stored
- # push each character onto the stack
- push:
- lb $t0,input($s0) # get current char into
- beqz $t0,end # null found at end of string
- addi $s0,$s0,-4
- sw $t0,0($s0) # holding the char
- addu $t1,1 # add 1 to the counter
- b push # go back to push untill end of string
- end:
- # pop chars from stack back into the buffer
- li $t1,0 # sets the couter to 0
- pop:
- lw $t0,($s0) # pop a char off the stack
- addu $s0,$s0,4
- beqz $t0,done # null means empty stack
- sb $t0,input($t1) # store string in $t1
- addu $t1,1 # add 1 to the counter
- b pop # go back to pop until end of string
- done:
- li $v0,4 # returns the string in reversed form
- la $a1,input # where the string is stored
- syscall
- li $v0, 4 # returns new line after the reverse string has been printed
- la $a0, blank # where the blank line is stored
- syscall
- li $v0,10 # exit program
- syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement