Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. .text
  2. main: la $t9,str #register address will always be the start of str
  3. li $t1,0 #t1 and t2 hold comparing bytes
  4. li $t2,0
  5.  
  6. in: li $v0,12 #prepares for syscall 12 where 1 letter is allowed to be input
  7. syscall
  8. move $t1,$v0 #loads the input into t1
  9. beq $t1,0x0a,in
  10. la $t0,str #resets t0 (current address register)
  11. j fowd
  12.  
  13. fowd: lb $t2,($t0) #loads current byte into t2
  14. beq $t2,$t1,shift #if this is the letter we are looking for, we go ahead and start moving forward to shift
  15. addi $t0,$t0,1 #otherwise, we move forward until it's the right letter
  16. j fowd
  17.  
  18. shift: lb $t3,1($t0) #gets letter after
  19. beqz $t3,bkshft #if next byte is zero, start moving backwards and shifting
  20. addi $t0,$t0,1 #otherwise, keep looking forward
  21. j shift
  22.  
  23. bkshft: lb $t5,($t0) #grab letter
  24. sb $t5,1($t0) #place letter one forward
  25. sub $t0,$t0,1 #move back a byte (starting from end of string)
  26. beq $t5,$t1,in #if we are at the right place, then our insertion is complete and we are ready for the next letter
  27. j bkshft
  28.  
  29.  
  30.  
  31. .data
  32. str: .asciiz "abcdefghijklmnopqrstuvwxyz"
  33. buffer: .space 30
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement