1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Input array values and output least value?

Discussion in 'Assembly Language Programming (ALP) Forum' started by ralphs22, Oct 5, 2015.

  1. ralphs22

    ralphs22 New Member

    Joined:
    Oct 5, 2015
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I am try to create an MIPS Assembly program that takes 5 values from a user and places them in an array. One the 5 values have filled the array, I want the program to output the least value in the array.

    I can cannot get the program to fill the array? Have any suggestions?

    Here is my code:
    Code:
    .data
    array:.space 24
    counter:.word 6
    least:	.word 0
    message0:.asciiz "The lowest number in the array is: "
    message1:.asciiz "Enter a value for array: "
    .text
    
    la $t1, array		#loads array address to t1
    li $t6, 0
    
    fillarray:
    li $v0, 4		#displays message1
    la $a0, message1
    syscall
    
    li $v0, 5
    syscall
    sw $v0, array($t1)
    
    add $t6, $t6, 4		#increments count+1
    add $t1, $t1, 4		#advances array[n]
    blt $t6, 24, fillarray	#If counter is less than 24 fillarray
    
    main:
    
    lw $t3, counter		#leads counter = 6 to t3
    lw $s5, ($t1)		#loads first value to s5
    add $t1, $t1, 4		#increments array[n]
    add $t3, $t3, -1	#decrements counter-1
    
    loop:
    lw $t4, ($t1)		#loads array[n] into t4
    ble $s5,$t4,L1		#if s5 <= t4
    move $s5, $t4		#moves new least value from t4 to s5
    
    L1:
    add $t3, $t3, -1	#decrement counter-1
    addi $t1, $t1, 4	#advances array[n]
    bnez $t3, loop		#if t3 is not equal to 0 loop again
    
    li $v0, 4		#displays message0
    la $a0, message0
    syscall
    
    sw $s5, least		#displays least value
    lw $a0, least
    li $v0, 1
    
    syscall  		#exits
    li $v0, 10
     

Share This Page