Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- ask: .asciiz "Please enter a string:\n"
- debug: .asciiz "\nentering loop first letter\n"
- debug1: .asciiz "\nentering loop 2 letter\n"
- debug2: .asciiz "\nOutput address: \n"
- tell: .asciiz "You wrote: "
- first: .asciiz "\nFirst letter is: "
- storedCounter: .word 0
- string: .space 256
- output: .space 1000
- .text
- .globl __start
- __start:
- la $a0, ask
- li $v0, 4
- syscall
- la $a0, string
- li $a1, 255
- li $v0, 8
- syscall
- la $a0, tell
- li $v0, 4
- syscall
- la $a0, string
- li $v0, 4
- syscall
- j CharacterLoop
- move $s1, $zero
- move $s2, $zero
- CharacterLoop:
- #################
- # #
- # First letter #
- # #
- #################
- la $a0, debug
- li $v0, 4
- #syscall
- lb $a2, string($s1)
- beq $a2, 10, EXIT
- lb $t1, string($s1) #load the first letter into $t1
- add $s1, $s1, 1
- srl $t9, $t1, 2 # shift right $t1 by 2, into $t2
- sll $t8, $t1, 6
- srl $t8, $t8, 8 #t8 will now hold the last 2 letters of the first word zero'd!!!!
- move $t9, $t8 #t9 is final holder for first letter, after it has been shifted
- #################
- # #
- # Second letter #
- # #
- #################
- la $a0, debug1
- li $v0, 4
- #syscall
- lb $t2, string($s1) #load the second letter into $t2
- beq $t2, 10, EXIT
- add $s1, $s1, 1
- srl $t3, $t2, 4 # shift right $t1 by 2, into $t2
- sll $t4, $t2, 28
- srl $t4, $t4, 26
- or $t8, $t9, $t3 #T8 holding the 2nd segment of the 3 chars
- #################
- # #
- # Third letter #
- # #
- #################
- move $t3, $zero
- lb $t3, string($s1) #load the third letter into $t3
- beq $t3, 10, EXIT
- add $s1, $s1, 1
- srl $t5, $t3, 6
- or $t6, $t4, $t5
- ###Get rid of the first 2 numbers from the third letter!
- sll $t7, $t3, 26
- srl $t7, $t7, 26
- ########################################################
- ## Move the "four" new letters into T1 through 4 ##
- ########################################################
- ##Output address
- la $a0, debug2
- li $v0, 4
- syscall
- la $a0, output
- li $v0, 1
- syscall
- move $t1, $t9
- move $t2, $t8
- move $t3, $t6
- move $t4, $t7
- sb $t1, output($s2)
- add $s2, $s2, 4
- sb $t2, output($s2)
- add $s2, $s2, 4
- sb $t3, output($s2)
- add $s2, $s2, 4
- sb $t4, output($s2)
- add $s2, $s2, 4
- la $a0, output+4
- li $v0, 4
- syscall
- j CharacterLoop
- EXIT:
- li $v0, 10
- syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement