I am trying to write a MIPS program that prints out the minimum of several integers that should each have 4-bytes. The program should prompt that user to enter the number of integers that will be entered, and then prompt for each of those integer numbers. It should then print out the minimum of the integers entered. Assuming that all user inputs are valid and the user inputs at least one integer number.
Here is the program that I tried on my own, but it doesn't to give the correct output:
################## DATA SECTION ##################
.data
prompt: .asciiz "\n How many integer numbers?(5 integers,minimum)"
result: .asciiz "The minimum integer is "
################## CODE SECTION ##################
.text
.globl main
main:
li $v0, 4 # system call code for Print String
la $a0, prompt # load address of prompt into $a0
syscall # print the prompt message
li $v0, 5 # system call code for Read Integer
syscall # reads the value into $v0
blez $v0, end # branch to end if $v0 < = 0
li $t0, 0 # clear register $t0 to zero
loop:
add $t0, $t0, $v0 # sum of integers in register $t0
addi $v0, $v0, -1 # summing integers in reverse order
bnez $v0, loop # branch to loop if $v0 is != zero
li $v0, 4 # system call code for Print String
la $a0, result # load address of message into $a0
syscall # print the string
li $v0, 1 # system call code for Print Integer
move $a0, $t0 # move value to be printed to $a0
syscall # print sum of integers
b main # branch to main
end: li $v0, 4 # system call code for Print String
la $a0, # load address of msg. into $a0
syscall # print the string
li $v0, 10 # terminate program run and
syscall # return control to system
1 Replies - 1018 Views - Last Post: 31 October 2012 - 06:37 PM
#1
Writing a MIPS program to find the minimum integer
Posted 31 October 2012 - 12:11 AM
Replies To: Writing a MIPS program to find the minimum integer
#2
Re: Writing a MIPS program to find the minimum integer
Posted 31 October 2012 - 06:37 PM
Ooooh, a dup topic! Please don't do that, you won't get help any faster
Page 1 of 1
|
|

New Topic/Question
This topic is locked



MultiQuote






|