3 Replies - 8428 Views - Last Post: 08 November 2012 - 06:41 AM

#1 832954  Icon User is offline

  • New D.I.C Head

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

Writing a MIPS assembly program to find the minimum integer

Posted 31 October 2012 - 06:28 PM

I am trying to write a MIPS assembly program that prints out the minimum of several integers entered by the user. Each integer is supposed to have 4-bytes. The program should prompt the 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 MIPS assembly program that I used on my own, but I cannot get 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 assembly 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 assembly program to find the minimum integer

Posted 31 October 2012 - 06:35 PM

Help us, help you. What output/errors are you getting? What output are you expecting?
Was This Post Helpful? 0
  • +
  • -

#3 832954  Icon User is offline

  • New D.I.C Head

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

Re: Writing a MIPS assembly program to find the minimum integer

Posted 31 October 2012 - 07:03 PM

View PostGunnerInc, on 31 October 2012 - 06:35 PM, said:

Help us, help you. What output/errors are you getting? What output are you expecting?


Here is the output that I am getting, but it's incorrect:

How many integer numbers? (5 integers, minimum)5
The minimum integer is 15
How many integer numbers? (5 integers, minimum)7
The minimum integer is 28
How many integer numbers? (5 integers, minimum)3
The minimum integer is 6
How many integer numbers? (5 integers, minimum)5
The minimum integer is 15
How many integer numbers? (5 integers, minimum)2
The minimum integer is 3
How many integer numbers? (5 integers, minimum)9
The minimum integer is 45

...and it doesn't stop asking you the same question(prompt) until you enter nothing.

The output is supposed to look something like this:

How many integer numbers? 5
Number[0]: 12
Number[1]: 3
Number[2]: -27
Number[3]: 8
Number[4]: -3

The minimum integer is: -27
Was This Post Helpful? 0
  • +
  • -

#4 turboscrew  Icon User is offline

  • D.I.C Addict

Reputation: 100
  • View blog
  • Posts: 615
  • Joined: 03-April 12

Re: Writing a MIPS assembly program to find the minimum integer

Posted 08 November 2012 - 06:41 AM

Does this:

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


mean that it just decrements the counter until it's zero and then
continues: prints the result and starts over?

I don't see any code where the integers are read in.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1