Question

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the MIPS code:
.text
main:
la $t0, NoOfStudents
lw $t0, 0($t0) #load the number of students
sll $t0, $t0, 2 #multiply the number of students by 4 (4 bytes in a word)
la $t1, Values #load the address of the array
li $t2, 0 #this is the array index, used for looping
li $t3, 0 #this is the counter for failed students
loop:
add $t4, $t1, $t2 #calculate loading address based on index
lw $t4, 0($t4) #load value from array
blt $t4, 60, incCounter #increment count if grade less than 60
j loopEnd
incCounter:
addi $t3, $t3, 1 #increment the counter
loopEnd:
addi $t2, $t2, 4 #increment the index by one word i.e. 4 bytes
blt $t2, $t0, loop #if end is not reached, loop again
move $a0, $t3 #print the answer
li $v0, 1
syscall
la $a0, printMessage #print the string for students failed
li $v0, 4
syscall
li $v0, 10 #exit the program
syscall
.data
NoOfStudents: .word 10
Values: .word 60 70 80 50 90 80 55 90 80 70
printMessage: .asciiz " students failed\n"

Here is a screenshot of the code:
.text main: la $to, Noofstudents lw $t0, 0($t0) #load the number of students sll $to, $to, 2 #multiply the number of students

Here is a screenshot of the output:
2 students failed

here is a screenshot of the output with the second array:
3 students failed

Comment in case of any doubts.

Add a comment
Know the answer?
Add Answer to:
Lab-3C   Pre-test Loop Write a MIPS program to count the number of students who failed in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ program that reads students' names followed by their test scores (5 scores) from the given...

    C++ program that reads students' names followed by their test scores (5 scores) from the given input file, students.txt. The program should output to a file, output.txt, each student's first name, last name, followed by the test scores and the relevant grade. All data should be separated by a single space. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, an array of testScores of type int...

  • Create a MIPS program that does the following: 4. Determine the letter grade a. Use the...

    Create a MIPS program that does the following: 4. Determine the letter grade a. Use the floating point calculated average to determine the letter grade. You will need to research the instructions to use to do comparisons with floating point numbers. (see Course Resources) b. Use the following chart: 90 - 100 80 - 89 70 - 79 ............. 60 - 69.............. <60 ..................... ............... 5. Display a message and the letter grade. 6. Your output should look similar to...

  • C++ Write a program that reads the number of students in the class, then reads each...

    C++ Write a program that reads the number of students in the class, then reads each student's name and his/her test score. Print out each student name, test score and grade, and the average score of the whole class. The program must use vectors and loops for the implementation. The grades are determined as follows: A >= 90; 80 <= B < 90; 70 <= C < 80; 60 <= D < 70; F < 60.

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • In C Langage Write a grading program for a class with the following grading policies:- a. There are two quizzes, each gr...

    In C Langage Write a grading program for a class with the following grading policies:- a. There are two quizzes, each graded on the basis of 10 points. b. There is one midterm exam and one final exam, each graded on the basis of 100 points. c. The final exam counts for 50 percent of the grade, the midterm counts for 25 percent and the two quizzes together count for a total of 25 percent. Grading system is as follows:-...

  • Write a C++ program. Using the while loop or the do – while loop write a...

    Write a C++ program. Using the while loop or the do – while loop write a program that does the following: Calculate the average of a series of homework grades (0 - 100) entered one at a time. In this case the lowest score will be dropped and the average computed with the remaining grades. For example suppose you enter the following grades: 78, 85, 81, 90, 88, 93 and 97.The average will be computed from the 6 grades 85,...

  • Enter a number rounded to one decimal. The syllabus states that a midterm test will count...

    Enter a number rounded to one decimal. The syllabus states that a midterm test will count for 30% of a student's course grade. The midterm is the first graded test in the course. After the midterm, three more tests-including the final-are scheduled. The final test counts for 50% of the student's course grade and the remaining tests count equally toward the final grade. Any bonus on a test is added to the test score before the result is entered into...

  • Write a grading program for the following grading policies:- a. There are two quizzes, each graded...

    Write a grading program for the following grading policies:- a. There are two quizzes, each graded on the basis of 10 points. b. There is one midterm exam and one final exam, each graded on the basis of 100 points. c. The final exam counts for 50 percent of the grade, the midterm counts for 25 percent and the two quizzes together count for a total of 25 percent. Grading system is as follows:- >90 A >=80 and <90 B...

  • Enter a number rounded to one decimal. The syllabus states that a midterm test will count...

    Enter a number rounded to one decimal. The syllabus states that a midterm test will count for 30% of a student's course grade. The midterm is the first graded test in the course. After the midterm, three more tests-including the final-are scheduled. The final test counts for 50% of the student's course grade and the remaining tests count equally toward the final grade. Any bonus on a test is added to the test score before the result is entered into...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT