Silver_Smoulder

[ASM] Addition/Subtraction/Comparison

Oct 17th, 2019
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. .globl main
  2. .text
  3.  
  4. main:
  5. li $v0, 4 #output the string
  6. la $a0, first_int
  7. syscall
  8.  
  9. li $v0, 5 #read in the number
  10. syscall
  11.  
  12. move $t0, $v0 #store first integer in t0
  13.  
  14. li $v0, 4 #output the string
  15. la $a0, second_int
  16. syscall
  17.  
  18. li $v0, 5 #read in the number
  19. syscall
  20.  
  21. move $t1, $v0 #store second integer in t1
  22.  
  23. bge $t0, $t1, bigger_m
  24. bge $t1, $t0, bigger_n
  25. beq $t0, $t1, equivalence
  26.  
  27. bigger_m:
  28. li $v0, 4 #output the string
  29. la $a0, m_big
  30. syscall
  31. j calc
  32.  
  33. bigger_n:
  34. li $v0, 4 #output the string
  35. la $a0, n_big
  36. syscall
  37. j calc
  38.  
  39. equivalence:
  40. li $v0, 4 #output the string
  41. la $a0, equality
  42. syscall
  43. j calc
  44.  
  45. calc:
  46. add $s0, $t0, $t0 #add m+m
  47. sub $s1, $t0, $t1 #subtract m-n
  48. sub $s2, $t0, 3 #subtract m-3
  49. add $s3, $t1, 4 #add n+4
  50.  
  51.  
  52.  
  53. #print out the line, then store the integer from the 's' registers to a0,
  54. #then print integer, then repeat
  55. li $v0, 4 #iteration 1
  56. la $a0, newline
  57. syscall
  58. move $a0, $s0
  59. li $v0, 1
  60. syscall
  61.  
  62. li $v0, 4 #iteration 2
  63. la $a0, newline
  64. syscall
  65. move $a0, $s1
  66. li $v0, 1
  67. syscall
  68.  
  69. li $v0, 4 #iteration 3
  70. la $a0, newline
  71. syscall
  72. move $a0, $s2
  73. li $v0, 1
  74. syscall
  75.  
  76. li $v0, 4 #iteration 4
  77. la $a0, newline
  78. syscall
  79. move $a0, $s3
  80. li $v0, 1
  81. syscall
  82.  
  83. li $v0, 10 #end the program
  84. syscall
  85.  
  86.  
  87. .data
  88. first_int:
  89. .asciiz "Please enter your first integer, M: "
  90. second_int:
  91. .asciiz "Please enter your second integer, N: "
  92. result:
  93. .asciiz "The sum of your integers is: "
  94. newline:
  95. .asciiz "\n"
  96. m_big:
  97. .asciiz "M is bigger than N"
  98. n_big:
  99. .asciiz "N is bigger than M"
  100. equality:
  101. .asciiz "M and N are equal"
Advertisement
Add Comment
Please, Sign In to add comment