Advertisement
Guest User

Untitled

a guest
May 31st, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. .data
  2. store: .space 40
  3. input: .asciiz "Please enter a intiger to store:"
  4. output: .asciiz "Your Smallest value is:"
  5. Cinput1: .asciiz "Enter the first value:"
  6. Cinput2: .asciiz "Enter the second value:"
  7. cOutput: .asciiz "The Combination Value is:"
  8. nl: .asciiz "\n"
  9. .text
  10. li $t0, 0 #counter for the array
  11. la $s0, store
  12. li $s1, 0 #min value
  13. li $s2, 10 #max value
  14.  
  15. main:
  16. add $t0, $t0 ,1
  17. la $a0, input #prints the input
  18. li $v0, 4
  19. syscall
  20.  
  21. li $v0, 5
  22. syscall
  23.  
  24. sw $v0, 0($s0) #stores the value in the bracket
  25. add $s0,$s0, 4
  26. bne $t0, 10, main #jump to main again until u have enough input
  27.  
  28. jal findMin # jump to find min value
  29.  
  30. la $a0, output #prints the outnput
  31. li $v0, 4
  32. syscall
  33.  
  34. move $a0,$s0 #this moves the top value
  35. li $v0, 1
  36. syscall
  37. b end
  38.  
  39.  
  40. findMin: #base case is when low=high return else get the position of the
  41. bne $s1,$s2,mrec
  42. mul $t3,$s1,4
  43. add $t1,$s0,$t3
  44. jr $ra
  45. mrec: #m
  46. add $t2,$s1,$s2
  47. li $t4, 2
  48. div $t2,$t2,$t4 # divide the value by 2
  49.  
  50. addi $sp,$sp,-40
  51. sw $ra ,0($sp)
  52. sw $s1 ,4($sp)
  53. sw $s2 ,8($sp)
  54. sw $t4 ,12($sp)
  55. sw $s0 ,20($sp)
  56.  
  57. move $s2,$t4
  58.  
  59. jal findMin
  60. sw $v0,16($sp)
  61.  
  62. lw $s0,20($sp)
  63. lw $t4,12($sp)
  64. addi $s1,$t4,1
  65. lw $s2,8($sp)
  66.  
  67. jal findMin
  68.  
  69. lw $t4,16($sp)
  70. bgt $t4,$v0, cleanUp
  71. move $v0,$t3
  72. cleanUp:
  73. lw $ra,0($sp)
  74. addi $sp,$sp,40
  75. jr $ra
  76.  
  77. end:
  78. li $v0,10
  79. syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement