Silver_Smoulder

[ASM] Hybrid Assignment 1

Oct 20th, 2019
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. .globl main
  2. .text
  3.  
  4. main:
  5. li $v0, 4 #prompt user for number of pairs
  6. la $a0, prompt_number
  7. syscall
  8.  
  9. li $v0, 5 #read in the number
  10. syscall
  11.  
  12. move $s0, $v0 #store value in t0
  13.  
  14. loop:
  15. li $v0, 4 #ask for and store the first number in t1
  16. la $a0, prompt_pair_1
  17. syscall
  18.  
  19. li $v0, 5 #read in the number
  20. syscall
  21. move $t1, $v0
  22.  
  23. li $v0, 4 #ask for and store the second number in t2
  24. la $a0, prompt_pair_2
  25. syscall
  26.  
  27. li $v0, 5 #read in the number
  28. syscall
  29. move $t2, $v0
  30.  
  31. add $s1, $s1, 1 #increment s1 every time we receive a pair of numbers
  32.  
  33. #our algorithm is going to be: double the second number, subtract it from the first, if the answer is 0 or below 0, we increment our counter
  34.  
  35. add $t2, $t2, $t2 #double the second number
  36. sub $t1, $t1, $t2 #subtract the second number from the first and store it in place of the first number
  37. blez $t1, bigger #jump to bigger
  38. beq $s0, $s1, exit #if the counter is equal to our prompt value, move to exit the program
  39. j loop #else jump to the start of the loop
  40.  
  41. bigger:
  42. add $t3, $t3, 1 #increment the "greater" counter once
  43. beq $s0, $s1, exit #if the counter is equal to our prompt value, move to exit the program
  44. j loop #else jump to the start of the loop
  45.  
  46. exit:
  47. la $a0, terminate
  48. move $a0, $t3 #put the integer into a0
  49. li $v0, 1 #output the integer
  50. syscall
  51.  
  52. li $v0, 10 #end the program
  53. syscall
  54.  
  55. .data
  56. prompt_number:
  57. .asciiz "Please input the total number of pairs you will have: "
  58. prompt_pair_1:
  59. .asciiz "Please enter the first number of your pair: "
  60. prompt_pair_2:
  61. .asciiz "Please enter the second number of your pair: "
  62. terminate:
  63. .asciiz "The program has finished executing. The condition of the second number being at least twice as big as the first has happened this many times: "
Advertisement
Add Comment
Please, Sign In to add comment