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

You have implemented a loop structure in the previous assignment. To improve the

ID: 3565606 • Letter: Y

Question

You have implemented a loop structure in the previous assignment. To improve the program structure, you need to put a part of the code that performs certain sub function into a procedure (method). In this question, you need to put the part of the MIPS code corresponding to the following high-level language code into a procedure:

if (W[i] > Max)

{

Max = W[i];

Winner = "Player " + Convert.ToString(i);

}

In the procedure, W[i] and Max must be treated a parameters (inputs), and the modified MAX value and the modified Winner value must treated as the return values (outputs) of the procedure.

The reserved registers for parameter passing and return value must be used for this purpose.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote