Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .text
- main: la $t9,str #register address will always be the start of str
- li $t1,0 #t1 and t2 hold comparing bytes
- li $t2,0
- in: li $v0,12 #prepares for syscall 12 where 1 letter is allowed to be input
- syscall
- move $t1,$v0 #loads the input into t1
- beq $t1,0x0a,in
- la $t0,str #resets t0 (current address register)
- j fowd
- fowd: lb $t2,($t0) #loads current byte into t2
- beq $t2,$t1,shift #if this is the letter we are looking for, we go ahead and start moving forward to shift
- addi $t0,$t0,1 #otherwise, we move forward until it's the right letter
- j fowd
- shift: lb $t3,1($t0) #gets letter after
- beqz $t3,bkshft #if next byte is zero, start moving backwards and shifting
- addi $t0,$t0,1 #otherwise, keep looking forward
- j shift
- bkshft: lb $t5,($t0) #grab letter
- sb $t5,1($t0) #place letter one forward
- sub $t0,$t0,1 #move back a byte (starting from end of string)
- beq $t5,$t1,in #if we are at the right place, then our insertion is complete and we are ready for the next letter
- j bkshft
- .data
- str: .asciiz "abcdefghijklmnopqrstuvwxyz"
- buffer: .space 30
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement