1 Replies - 1805 Views - Last Post: 31 October 2012 - 06:37 PM Rate Topic: -----

#1 832954  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-October 12

Writing a MIPS program to find the minimum integer

Posted 31 October 2012 - 12:11 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Writing a MIPS program to find the minimum integer

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,277
  • Joined: 28-March 11

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1