Silver_Smoulder

[ASM] Upper to Lower by prof

Oct 24th, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #Input 2 digits, each as a character, convert them to numbers, add and output
  2.  
  3. .text
  4. .globl main
  5.  
  6. main:
  7. la $a0, m1 #what to output (contents of m1)
  8. li $v0, 4 # Display a message.
  9. syscall
  10.  
  11. la $a0, Instr #where to put input
  12. li $a1, 4 # Length in a1-last must be enter (this actually # gets 3 digits).
  13. li $v0, 8 # Read Input string.
  14. syscall
  15.  
  16. li $t1, 0 #get address of input
  17. li $t2,32 # amount to add to make lower case
  18. addi $a1,$a1,-1 #since actually got 3 digits set counter to 3
  19. getdigit:
  20. lb $t0, Instr($t1) # Load from the address in t1
  21. add $t0, $t0,$t2 #make it a lower case
  22. sb $t0,Instr($t1)
  23.  
  24.  
  25. addi $t1,$t1,1 #go to next digit
  26. addi $a1,$a1,-1 #is it a digit
  27. bgt $a1, $0, getdigit #if not done continue
  28.  
  29. la $a0, m6 #Prints message.
  30. li $v0 4
  31. syscall
  32. la $a0,Instr
  33. li $v0 4
  34. syscall
  35. end:
  36.  
  37. la $a0, m8 #Prints Goodbye.
  38. li $v0 4
  39. syscall
  40.  
  41. la $v0,10
  42. syscall # au revoir...
  43.  
  44. ###########################################################
  45. # data segment
  46. ###########################################################
  47.  
  48. .data
  49. m1: .asciiz "Enter a 3 letter word in all upper case \n "
  50. m6: .asciiz "\nIn lower case is: \n "
  51. m8: .asciiz "\nGoodbye!\n" #For exiting.
  52. .align 2
  53. Instr: .space 10 # Space for in string.
  54.  
  55. ## end of file.
Advertisement
Add Comment
Please, Sign In to add comment