Silver_Smoulder

[ASM} Memory Management by Prof

Oct 23rd, 2019
241
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, 3 # Length in a1-last must be enter (this actually # gets 3 digits).
  13. li $v0, 8 # Read Input string.
  14. syscall
  15.  
  16. la $t1, Instr #get address of input
  17. li $t2,48 # amount to subtract to make ASCII decimal
  18. addi $a1,$a1,-1 #since actually got 3 digits set counter to 3
  19. getdigit:
  20. lb $t0, ($t1) # Load from the address in t1
  21. sub $t0, $t0,$t2 #make it a digit
  22.  
  23. la $a0, m6 # print a newline.
  24. li $v0 4
  25. syscall
  26.  
  27. move $a0, $t0
  28. li $v0 1 #print number
  29. syscall
  30.  
  31. addi $t1,$t1,1 #go to next digit
  32. addi $a1,$a1,-1 #is it a digit
  33. bgt $a1, $0, getdigit #if not done continue
  34. end:
  35. la $a0, m8 #Prints Goodbye.
  36. li $v0 4
  37. syscall
  38.  
  39. la $v0,10
  40. syscall # au revoir...
  41.  
  42. ###########################################################
  43. # data segment
  44. ###########################################################
  45.  
  46. .data
  47. m1: .asciiz "Enter a Number \n "
  48. m6: .asciiz "\nThe digit is: \n "
  49. m8: .asciiz "\nGoodbye!\n" #For exiting.
  50. .align 2
  51. Instr: .space 10 # Space for in string.
  52.  
  53. ## end of file.
Advertisement
Add Comment
Please, Sign In to add comment