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

Programming Assignment. Use the MARS simulator to write and test a MIPS assembly

ID: 441542 • Letter: P

Question

Programming Assignment. Use the MARS simulator to write and test a MIPS assembly language program (named grades.asm) that ---Reads three grades from standard input. Before reading the values, include a single prompt of Enter three grades: ---Computes the integer average, and ---Prints the results as follows The avg = #### where #### is the average grade. An assembly language program does not have to fully memic a solution in a high-level language. Thus, this assignment does not require the use of variables in which to store the various integer values. Of course, the strings will have to be stored in order to display the prompt and the results.

Explanation / Answer

Hi,


Below is the code to find the average grade of three grades.


.text

.globl avgs

avgs:

# program to print the average grades from three grades

li $v0, 4

la $a0, prompt1

syscall

li $v0, 5 # read keyboard into $v0

syscall

move $t0,$v0 # first grade in $t0

li $v0, 5 # read keyboard into $v0

syscall

move $t1,$v0 # second grade in $t1

li $v0, 5 # read keyboard into $v0

syscall

move $t2,$v0 # third grade in $t2

add $t0,$t1,$t2 # total the grades

li $t3,3

div $t0,$t3 # compute average

mflo $t6 # move result

li $a0,$t6 # average value

jal itoa

move $a0,$t6

# Copy first string to result buffer

la $a0,answer1

la $a1,result

jal cpystr

# Concatenate second string on result buffer

la $a0,$t6

or $a1,$v0, $zero

jal cpystr

j finish

nop

# String copier function

cpystr:

or $t0, $a0, $zero # Source

or $t1, $a1, $zero # Destination

loop:

lb $t2, 0($t0)

beq $t2, $zero, end

addiu $t0, $t0, 1

sb $t2, 0($t1)

addiu $t1, $t1, 1

b loop

nop

end:

or $v0, $t1, $zero # Return last position on result buffer

jr $ra

nop

finish:

li $v0, 4

la $a0, result

syscall

jr $31 # return to operating system

.data

prompt1: .asciiz "Enter the three grades "

answer1: .asciiz "The avg = "

result: .space 200



Hope this helps. Excuse me if any typos.


Thanks,