Guest User

Untitled

a guest
Jun 11th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     .data
  2. string:     .asciiz     "Hello dark magic world!"
  3. newLine:    .asciiz     "\n"
  4. copySpace:  .space      64  # 64 bytes for string copies
  5.  
  6.  
  7.     .text
  8. main:
  9. la  $t0, string # load string address
  10. la  $t1, copySpace  # load free space address
  11. la  $t2, string # load current character address
  12.  
  13. # iterate to the end of the string
  14. check_next_elem:
  15. lb  $t3, ($t2)  # load current character
  16. beqz    $t3, string_end # if null
  17. addi    $t2, $t2, 1 # update current character address
  18. j   check_next_elem
  19.  
  20. string_end:
  21. addi    $t2, $t2, -1    # update current character address to last element address
  22.  
  23. # iterate through the string in reverse order
  24. addi    $t5, $t1, 0 # address to copy current character to
  25. check_previous_elem:
  26. sub $t3, $t2, $t0   # get current character index
  27. bltz    $t3, all_elements_copied    # if index is less then 0
  28. lb  $t3, ($t2)  # load current character
  29. check_if_big_letter:
  30. sub $t4, $t3, 'A'
  31. bltz    $t4, copy_char # if current character is less then 'A' it is not small nor big letter
  32. sub $t4, $t3, 'Z'
  33. bgtz    $t4, check_if_small_letter # if current character is greater then 'Z' it is not big letter
  34. addi    $t3, $t3, 32    # it is big letter, change to small one
  35. j   copy_char
  36. check_if_small_letter:
  37. sub $t4, $t3, 'a'
  38. bltz    $t4, copy_char # if current character is less then 'a' it is not small letter
  39. sub $t4, $t3, 'z'
  40. bgtz    $t4, copy_char # if current character is greater then 'z' it is not small letter
  41. addi    $t3, $t3, -32   # it is small letter, change to big one
  42. copy_char:
  43. sb  $t3, ($t5)  # store updated current character
  44. addi    $t5, $t5, 1 # update address to copy current character to
  45. addi    $t2, $t2, -1    # update current character address
  46. j   check_previous_elem
  47.  
  48. all_elements_copied:
  49. li  $t3, 0 
  50. sb  $t3, ($t5)  # add null (0) after all characters
  51.  
  52. # print strings
  53. li  $v0, 4      # load appropriate system call code into register $v0, code for printing string is 4
  54. la  $a0, string # load address of string to be printed into $a0
  55. syscall
  56. li  $v0, 4      # load appropriate system call code into register $v0, code for printing string is 4
  57. la  $a0, newLine    # load address of string to be printed into $a0
  58. syscall
  59. li  $v0, 4      # load appropriate system call code into register $v0, code for printing string is 4
  60. la  $a0, copySpace  # load address of string to be printed into $a0
  61. syscall
  62.  
  63. exit:
  64. addi $v0, $0, 10        # System call code for exit.
  65. syscall
Advertisement
Add Comment
Please, Sign In to add comment