?
Solved

Assembly Language in MIPS

Posted on 2011-05-10
5
Medium Priority
?
698 Views
Last Modified: 2012-05-11
I need to find the minimum number entered. That is the smallest number entered. Any help. My code is returning a zero for the minimum. that is if i entered 1,2,3,4,5,6,7,8,9,10 the minimum return should be 1.


.data
array:  .space 40  
prompt: .asciiz "Enter a number: " 
spacee: .asciiz " "
output: .asciiz "The numbers are: "
minimum_Int: .asciiz "\nThe minimum number is : "
        .globl main
        .text
main:
 li $t1,10         #load 10 into $t1
 li $t7, 0        # $t7 minimum number entered
 la $a1,array      #load a pointer to array into $a1

loop:
 addi $t1,$t1,-1   #subtract 1 from $t1, save to $t1
 li $v0,4          #load 4 into $v0 (print string)
 la $a0,prompt     #load prompt text into $a
 syscall           #display prompt
 li $v0,5          #load 5 into $v0 (read integer)
 syscall           #prompt for input
 blt $v0, $t7, minimum     # Branch if number is smaller
 sw $v0,0($a1)     #store input int to array
 #blt $v0, $t7, minimum     # Branch if number is smaller
 addi $a1,$a1,4    #add 4 to $a1, save to $a1
 bnez $t1,loop     #if $t1 isn't zero,goto loop
 li $t1,9          #if $t1 is zero, load 9 into $t1
 li $t2,9          #and load 9 into $t2
 la $a1,array      #load array pointer into $a1
 

 
loop1:
 beqz $t2,here     #if $t2 is zero, goto here
 addi $t2,$t2,-1   #subtract 1 from $t2, save to $t2
 lw $t5,0($a1)     #load an input int into $t5
 lw $t6,4($a1)     #load the next one into $t6
 addi $a1,$a1,4    #add 4 to $a1, save to $a1
 ble $t5,$t6,loop1 #if $t5 <= $t6, goto loop1
 sw $t5,0($a1)     #else, store $t5 in $a1
 sw $t6,-4($a1)     #and store $t6 in $a1-4 (swapping them)
 bnez $t2,loop1    #if $t2 is not zero, to go loop1
 
 li $v0, 1                 # system call code for print string
 syscall                   # print prompt
 

here:
 la $a1,array      #load array into $a1
 addi $t1,$t1,-1   #subtract 1 from $t1, save to $t1
 add $t2,$t2,$t1   #add $t2 to $t1, save to $t2
 bnez $t1,loop1    #if $t1 isn't zero, goto loop1
 li $v0,4          #load 4 into $v0 (print string)
 la $a0,output     #load 'the numbers are' into $a0
 syscall           #display message to screen
 la $a1,array      #load array pointer into $a1
 li $t1,10         #load 10 into $t1

loop2:
 li $v0,1          #load 1 into $v0 (print int)
 lw $a0,0($a1)     #load $a1 into $a0
 blt $a0, $t7 minimum
 syscall           #print first number to screen
 li $v0,4          #load 4 into $v0 (print string)
 la $a0,spacee     #load ' ' into $a0
 syscall           #print ' ' to screen
 addi $a1,$a1,4    #add 4 to $a1, save to $a1
 addi $t1,$t1,-1   #subtract 1 from $t1, save to $t1
 
 
 bnez $t1,loop2    #if $t1 isn't zero, goto loop2
 
 minimum:
 li $v0, 4                 # system call code for print string
 la $a0, minimum_Int       # print string "The smallest of numbers entered is : "
 syscall                   # print prompt
 
 li $v0, 1                 # system call code for print string
 move $a0, $t7             # print smallest number
 syscall                   # print prompt
 
 
 li $v0,10              #exit

 syscall
0
Comment
Question by:oparebea
  • 4
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35729317
Why do you have the branch at line 21? Shouldn't you wait until you receive all numbers prior to checking for the minimum?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35729714
I see that you have sorted the array. Why not load the first slot of the array an print that?
la $a0, array
lw $a0, 0($a0)

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1500 total points
ID: 35729773
Never mind the first comment. I see now what you are doing.
0
 

Author Closing Comment

by:oparebea
ID: 35746899
The solution helped but partially
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35751815
The solution helped but partially
For my own edification, how so?
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
This article will show, step by step, how to integrate R code into a R Sweave document
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses
Course of the Month17 days, 2 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question