Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a MIPS program to find the maximum score of a weight-lifting competition.

ID: 3564057 • Letter: W

Question

write a MIPS program to find the maximum score of a weight-lifting competition. For example, if there are 5 players, the program needs to take 5 integers from the keyboard. The definition of the problem is: Input: Given a list of numbers from the keyboard, representing the weights lifted by players Output: Find the largest weight, representing the winner.

write a MIPS program to find the maximum score of a weight-lifting competition. For example, if there are 5 players, the program needs to take 5 integers from the keyboard. The definition of the problem is: Input: Given a list of numbers from the keyboard, representing the weights lifted by players Output: Find the largest weight, representing the winner.

Explanation / Answer

.data
number:.asciiz "Enter the number of players : "
enter: .asciiz "Enter the weight of player "
newline: .asciiz " "
player: .asciiz "Player "
wins: .asciiz" wins with weight = "
weight: .space 20 #20 bytes to store the weight of each player.assuming at max 20 players and the weight of each player doesnot exceed 255
numberplayers: .space 1
.text
#ask for number of players-maximum of 20 is allowed
li $v0,4
la $a0,number
syscall
li $v0,5
syscall
la $a0,numberplayers
sb $v0,0($a0)

la $a0,numberplayers
lbu $t0,0($a0)
li $t2,0
la $t1,weight
next:
#ask the user to enter the weight
li $v0,4
la $a0,enter
syscall
#print the current player number
li $v0,1
move $a0,$t2
syscall
#print new line for proper formatting
li $v0,4
la $a0,newline
syscall
#read the weight entered
li $v0,5
syscall
#store the weight enterd in the array
sb $v0,0($t1)
#increment the pointer to array
addi $t1,$t1,1
#drement the counter
subi $t0,$t0,1
#increment the player number
addi $t2,$t2,1
#repeat for all the 5 players
bgt $t0,$0,next
#all the players weights are recorded.
#load the address of array
la $t1,weight
li $t2,0#initialise the maximum with 0
li $t4,0#initialize the player index to 0

#loop for the total number of players stored in numberplayers
la $a0,numberplayers
lbu $t0,0($a0)
again:
lbu $t3,0($t1) # read the weight
bgt $t2,$t3,skip #if the read weight is greater then modify the $t2 else skip
move $t2,$t3 #update $t2 with the read value.
la $a0,numberplayers
lbu $a0,0($a0)
sub $t4,$a0,$t0
skip:
#decrement the counter
subi $t0,$t0,1
#increment the address
addi $t1,$t1,1
bgt $t0,$0,again

li $v0,4
la $a0,player
syscall

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


li $v0,4
la $a0,wins
syscall

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

li $v0,10
syscall