Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the SPIM assembly language program loop1.s . Solution Program Name: min

ID: 1847330 • Letter: C

Question

Complete the SPIM assembly language program loop1.s.

Explanation / Answer

Program Name: min-max.s ## ## - will print out the minimum value min ## - and the maximum value max of an array. ## ## - Assume the array has at least two elements (a[0] and a[1]). ## - It initializes both min and max to a[0] and then ## - goes through the loop count - 1 times. ## - This program will use pointers. ## ## ## t0 - point to array elements in turn ## t1 - contains count of elements ## t2 - contains min ## t3 - contains max ## t4 - each word from array in turn ## ################################################# # # # text segment # # # ################################################# .text .globl __start __start: # execution starts here la $t0,array # $t0 will point to the elements lw $t1,count # exit loop when $t1 == 0 lw $t2,($t0) # initialize min = a[0] lw $t3,($t0) # initialize max = a[0] add $t0,$t0,4 # pointer to start at a[1] add $t1,$t1,-1 # and go round count - 1 times loop: lw $t4,($t0) # load next word from array bge $t4,$t2,notMin # skip if a[i] >= min move $t2,$t4 # copy a[i] to min notMin: ble $t4,$t3,notMax # skip if a[i] 0 la $a0,ans1 # print prompt on terminal li $v0,4 # system call to print syscall # out "min = " move $a0,$t2 # print result min li $v0,1 syscall la $a0,ans2 # print out "max = " li $v0,4 syscall move $a0,$t3 # print result max li $v0,1 syscall la $a0,endl # syscal to print out li $v0,4 # a new line syscall li $v0,10 # Exit syscall # Bye! ################################################# # # # data segment # # # ################################################# .data array: .word 3,4,2,6,12,7,18,26,2,14,19,7,8,12,13 count: .word 15 ans1: .asciiz "min = " ans2: .asciiz " max = " endl: .asciiz " " ## ## end of file min-max.s
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote