Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. .data
  2. input: .space 41
  3. blank: .asciiz "\n"
  4. .text
  5. .globl main
  6. main:
  7.  
  8. #input the string
  9. li $v0,8 # service code
  10. la $a0,input # address of buffer
  11. li $a1,41 # buffer length
  12. syscall
  13.  
  14. li $t0,0 # push null onto stack
  15. addi $s0,$s0,-4
  16. sw $t0,($s0) # this indicates the bottom of the stack
  17. li $t1,0 # where the first character of the string is stored
  18.  
  19.  
  20.  
  21.  
  22.  
  23. # push each character onto the stack
  24.  
  25. push:
  26.  
  27. lb $t0,input($s0) # get current char into
  28. beqz $t0,end # null found at end of string
  29. addi $s0,$s0,-4
  30. sw $t0,0($s0) # holding the char
  31. addu $t1,1 # add 1 to the counter
  32. b push # go back to push untill end of string
  33.  
  34. end:
  35.  
  36. # pop chars from stack back into the buffer
  37.  
  38. li $t1,0 # sets the couter to 0
  39.  
  40. pop:
  41.  
  42. lw $t0,($s0) # pop a char off the stack
  43. addu $s0,$s0,4
  44. beqz $t0,done # null means empty stack
  45.  
  46. sb $t0,input($t1) # store string in $t1
  47. addu $t1,1 # add 1 to the counter
  48. b pop # go back to pop until end of string
  49.  
  50. done:
  51.  
  52. li $v0,4 # returns the string in reversed form
  53. la $a1,input # where the string is stored
  54. syscall
  55.  
  56. li $v0, 4 # returns new line after the reverse string has been printed
  57. la $a0, blank # where the blank line is stored
  58. syscall
  59.  
  60. li $v0,10 # exit program
  61. syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement