Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- string: .asciiz "Hello dark magic world!"
- newLine: .asciiz "\n"
- copySpace: .space 64 # 64 bytes for string copies
- .text
- main:
- la $t0, string # load string address
- la $t1, copySpace # load free space address
- la $t2, string # load current character address
- # iterate to the end of the string
- check_next_elem:
- lb $t3, ($t2) # load current character
- beqz $t3, string_end # if null
- addi $t2, $t2, 1 # update current character address
- j check_next_elem
- string_end:
- addi $t2, $t2, -1 # update current character address to last element address
- # iterate through the string in reverse order
- addi $t5, $t1, 0 # address to copy current character to
- check_previous_elem:
- sub $t3, $t2, $t0 # get current character index
- bltz $t3, all_elements_copied # if index is less then 0
- lb $t3, ($t2) # load current character
- check_if_big_letter:
- sub $t4, $t3, 'A'
- bltz $t4, copy_char # if current character is less then 'A' it is not small nor big letter
- sub $t4, $t3, 'Z'
- bgtz $t4, check_if_small_letter # if current character is greater then 'Z' it is not big letter
- addi $t3, $t3, 32 # it is big letter, change to small one
- j copy_char
- check_if_small_letter:
- sub $t4, $t3, 'a'
- bltz $t4, copy_char # if current character is less then 'a' it is not small letter
- sub $t4, $t3, 'z'
- bgtz $t4, copy_char # if current character is greater then 'z' it is not small letter
- addi $t3, $t3, -32 # it is small letter, change to big one
- copy_char:
- sb $t3, ($t5) # store updated current character
- addi $t5, $t5, 1 # update address to copy current character to
- addi $t2, $t2, -1 # update current character address
- j check_previous_elem
- all_elements_copied:
- li $t3, 0
- sb $t3, ($t5) # add null (0) after all characters
- # print strings
- li $v0, 4 # load appropriate system call code into register $v0, code for printing string is 4
- la $a0, string # load address of string to be printed into $a0
- syscall
- li $v0, 4 # load appropriate system call code into register $v0, code for printing string is 4
- la $a0, newLine # load address of string to be printed into $a0
- syscall
- li $v0, 4 # load appropriate system call code into register $v0, code for printing string is 4
- la $a0, copySpace # load address of string to be printed into $a0
- syscall
- exit:
- addi $v0, $0, 10 # System call code for exit.
- syscall
Advertisement
Add Comment
Please, Sign In to add comment