#********************************************************************** # CS 232: Comp. Arch. I # Written: 12/6/99, JP Mellor # # This file contains procedure: # -- main # # The program prints the minimum # element of an array in memory # #********************************************************************** .globl main .globl V .data V: .word 20, 56, -90, 37, -2, 30, 10, -66, -4, 18 message: .asciiz "Minimum element -> " newline: .asciiz "\n" #********************************************************************** .text main: #---------------------------------------------------------------------- # Find the minimum element of V #---------------------------------------------------------------------- li $t1, 10 # load end - number of elements in V sll $t1, $t1, 2 # multiply end by 4 to get word addresses li $t0, 0 # initialize index lw $t2, V($t0) # initialize min with the first element add $t0, $t0, 4 # increment the index beq $t0, $t1, exit # check if we've processed the last element loop: lw $t3, V($t0) # read the next element of the array slt $t4, $t3, $t2 # check if it's less than the min beq $t4, $zero, skip# if not skip move $t2, $t3 # if it is update min skip: add $t0, $t0, 4 # increment the index bne $t0, $t1, loop # check if we've processed the last element #---------------------------------------------------------------------- # Print the answer #---------------------------------------------------------------------- exit: la $a0, message # store pointer to message li $v0, 4 # use system call to syscall # print message move $a0, $t2 # store min li $v0, 1 # use system call to syscall # print the min la $a0, newline # store pointer to a new line li $v0, 4 # use system call to syscall # print new line # --------------------------------------------------------------------- # Exit # --------------------------------------------------------------------- li $v0, 10 # use system call to syscall # exit