1 Replies - 2211 Views - Last Post: 19 March 2013 - 03:59 PM

#1 K90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-March 13

MIPS:finding the maximum number,problem/question...

Posted 18 March 2013 - 01:21 AM

Hello there, I am still very new to programming in general.. I have an MIPS assignment, the assignment is to write a program which will display the largest number of 4 entered numbers by the user... The code below is what I have tried so far, but I don't know how to generate a loop that will read all the entered numbers.. If anyone can help me just a little so I can make this code work as wanted, I will be more than grateful..thank you all!

 
.text

la $a0,msg1
li $v0,4
syscall 
li $v0,5
syscall
move $t0,$v0

la $a0,msg2
li $v0,4
syscall 
li $v0,5
syscall
move $t1,$v0

la $a0,msg3
li $v0,4
syscall 
li $v0,5
syscall
move $t2,$v0

la $a0,msg4
li $v0,4
syscall 
li $v0,5
syscall
move $t3,$v0 #Displaying messages

move $s0, $t0 # max=A[0]
main:
 
li $t7,0
slti $t5,$t7,4
beq $t5,1,LOOP
addi $t7,$t7,1
nop
j end
nop

LOOP:
bgt $t1,$s0,m
m:
move $s0,$t1


bgt $t2,$s0,m1
m1:
move $s0,$t2

bgt $s0,$t3,m2
m2:
move $s0,$t3



end:
la $a0,Result
li $v0,4
syscall

li $v0,1
move $a0,$s0
syscall 





.data
msg1: .asciiz "Enter number 1:"
msg2: .asciiz "Enter number 2:"
msg3: .asciiz "Enter number 3:"
msg4: .asciiz "Enter number 4:"




Is This A Good Question/Topic? 0
  • +

Replies To: MIPS:finding the maximum number,problem/question...

#2 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1156
  • View blog
  • Posts: 2,538
  • Joined: 05-May 05

Re: MIPS:finding the maximum number,problem/question...

Posted 19 March 2013 - 03:59 PM

Why do you want to write a loop when you have something that works? Here's a small tutorial on writing loops. You should really try and comment your code as well.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1