Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- BufferSize: .word 32
- Newline: .asciiz "\r\n"
- Separator_Text: .asciiz " => "
- Prompt_Text: .asciiz "Enter a string: "
- .text
- main:
- jal prompt
- jal print_separator
- jal loop_start
- jal print_string
- j exit
- prompt:
- # Print prompt string
- li $v0, 4
- la $a0, Prompt_Text
- syscall
- # Alloc string buffer
- li $v0, 9
- lw $a0, BufferSize
- syscall
- # Read string input, $s0 contains beginning of string addr
- move $s0, $v0
- move $a0, $s0
- li $v0, 8
- lw $a1, BufferSize
- syscall
- # Reset index
- li $s1, 0
- # Return
- jr $ra
- # Preserve return address and begin loop
- loop_start:
- move $s2, $ra
- j loop
- # Loop through characters in buffer
- loop:
- lw $t0, BufferSize
- bge $s1, $t0, loop_done
- jal tolower
- addi $s1, $s1, 1
- j loop
- # Return to preserved address
- loop_done:
- jr $s2
- # $s0 - Base String Address
- # $s1 - Byte Index
- tolower:
- # Load byte
- add $t0, $s0, $s1
- lb $t1, ($t0)
- # Check if uppercase character
- li $t2, 65
- blt $t1, $t2, tolower_skip
- li $t2, 90
- bgt $t1, $t2, tolower_skip
- # Perform lowercase change
- addi $t1, $t1, 32
- # Store byte
- sb $t1, ($t0)
- # Return
- jr $ra
- tolower_skip:
- jr $ra
- # Print separator string
- print_separator:
- li $v0, 4
- la $a0, Separator_Text
- syscall
- jr $ra
- # Print string @ addr in $s0
- print_string:
- li $v0, 4
- la $a0, ($s0)
- syscall
- jr $ra
- exit:
- li $v0, 10
- syscall
Add Comment
Please, Sign In to add comment