Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- store: .space 40
- input: .asciiz "Please enter a intiger to store:"
- output: .asciiz "Your Smallest value is:"
- Cinput1: .asciiz "Enter the first value:"
- Cinput2: .asciiz "Enter the second value:"
- cOutput: .asciiz "The Combination Value is:"
- nl: .asciiz "\n"
- .text
- li $t0, 0 #counter for the array
- la $s0, store
- li $s1, 0 #min value
- li $s2, 10 #max value
- main:
- add $t0, $t0 ,1
- la $a0, input #prints the input
- li $v0, 4
- syscall
- li $v0, 5
- syscall
- sw $v0, 0($s0) #stores the value in the bracket
- add $s0,$s0, 4
- bne $t0, 10, main #jump to main again until u have enough input
- jal findMin # jump to find min value
- la $a0, output #prints the outnput
- li $v0, 4
- syscall
- move $a0,$s0 #this moves the top value
- li $v0, 1
- syscall
- b end
- findMin: #base case is when low=high return else get the position of the
- bne $s1,$s2,mrec
- mul $t3,$s1,4
- add $t1,$s0,$t3
- jr $ra
- mrec: #m
- add $t2,$s1,$s2
- li $t4, 2
- div $t2,$t2,$t4 # divide the value by 2
- addi $sp,$sp,-40
- sw $ra ,0($sp)
- sw $s1 ,4($sp)
- sw $s2 ,8($sp)
- sw $t4 ,12($sp)
- sw $s0 ,20($sp)
- move $s2,$t4
- jal findMin
- sw $v0,16($sp)
- lw $s0,20($sp)
- lw $t4,12($sp)
- addi $s1,$t4,1
- lw $s2,8($sp)
- jal findMin
- lw $t4,16($sp)
- bgt $t4,$v0, cleanUp
- move $v0,$t3
- cleanUp:
- lw $ra,0($sp)
- addi $sp,$sp,40
- jr $ra
- end:
- li $v0,10
- syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement