Question

In: Computer Science

Lab-3C   Pre-test Loop Write a MIPS program to count the number of students who failed in...

Lab-3C   Pre-test Loop

Write a MIPS program to count the number of students who failed in a course. The final grades are given in an array. The fail grade is 60.

Example: Array and Output

     .data

NoOfStudents: 10

Values:   60 70 80 50 90 80 55 90 80 70

Output:

2 students failed

     .data

NoOfStudents: 12

Values:   60 70 80 50 90 80 55 90 80 70 55 80

Output:

3 students failed

Solutions

Expert Solution

Given below is the code for the question. Please do rate the answer if it helped. Thank you.

.data
numStudents: .word 12
grades: .word 60 70 80 50 90 80 55 90 80 70 55 80
msg: .asciiz " students failed"

.text
   lw $t0, numStudents #read the size
   li $t1, 0 #initialize loop counter
   la $t2, grades #get address of first array element
   li $t3, 0 #no. of student who failed
  
loop:
   bge $t1, $t0, endloop
   lw $t4, ($t2) #read the current number
   bge $t4, 60, next #not fail student
   add $t3, $t3, 1
next:
   add $t1, $t1, 1 #increment loop counter
   add $t2, $t2, 4 #next element address
   b loop

endloop:
   #print results
  
   #print int
   move $a0, $t3
   li $v0, 1
   syscall


   #print string
   li $v0, 4
   la $a0, msg
   syscall
  
   #exit
   li $v0, 10
   syscall


output
-----

3 students failed
-- program is finished running --


Related Solutions

2.c++ if and loop statement Write a program that will count the number of even number...
2.c++ if and loop statement Write a program that will count the number of even number and odd numbers between two inputted numbers. Display the numbers and compute the sum and average of all the even numbers and the sum and average all the odd numbers. Sample outputs: Enter starting number:3 Enter starting number:4 Enter ending number:10 Enter ending number:10 odd numbers Even number 3 4 5 6 7 8 9 10 number of even numbers=4 number of even numbers=4...
Count the number of 1’s and 0’s Write a MIPS program that will ask the user...
Count the number of 1’s and 0’s Write a MIPS program that will ask the user to enter an integer, and then output the number of 1’s and 0’s that are present in the integer’s signed 32-bit binary representation. For example, 15 has a binary representation of 0000 0000 0000 0000 0000 0000 0000 1111, which has 28 zeroes and 4 ones. We have provided you the starter code that deals with the input/output logic. The integer input is saved...
In C++ For this assignment, you will write a program to count the number of times...
In C++ For this assignment, you will write a program to count the number of times the words in an input text file occur. The WordCount Structure Define a C++ struct called WordCount that contains the following data members: An array of 31 characters named word An integer named count Functions Write the following functions: int main(int argc, char* argv[]) This function should declare an array of 200 WordCount objects and an integer numWords to track the number of array...
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results).
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results). (Make sure you use comments next to each line to describe what actions you are taking in your code. )...
Write a Python program that has a loop to continuously ask the user for a number,...
Write a Python program that has a loop to continuously ask the user for a number, terminating the loop when the number entered is -1. Inside the loop, 1.) display one asterisk(*) if the number is 1, 2.) two asterisk(**) if the number is 2 and 3.) "OTHER" if the number is any other number.
Write a program in MIPS assembly language to convert an ASCII number string containing positive and...
Write a program in MIPS assembly language to convert an ASCII number string containing positive and negative integer decimal strings, to an integer. Your program should expect register $a0 to hold the address of a nullterminated string containing some combination of the digits 0 through 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register $v0. If a non-digit character appears anywhere in the string, your program should stop with...
Do the following lab by while or Do-while loop. question: Write a c++ program that asks...
Do the following lab by while or Do-while loop. question: Write a c++ program that asks students to enter 3 valid grades and then calculate the average and print it. if the user enters the invalid grade you should print the error message and get the new grade. Hint1: each time your program ask the following question: "Do you want to calculate another average?" and if the answer to this question is "Y" or "y" then you should continue. Hint2:...
Write a Java loop statement that prints count. Count begins with 1. It increments as multiples...
Write a Java loop statement that prints count. Count begins with 1. It increments as multiples of 2 and does the loop until count is less than 50.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT