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...
write a mips program to find the number of elements of the array that are divisible...
write a mips program to find the number of elements of the array that are divisible by 3.
write a MIPS program to ask user to input the number of elements of array
write a MIPS program to ask user to input the number of elements of array
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...
In Java: Write a program that will count the number of characters, words, and lines in...
In Java: Write a program that will count the number of characters, words, and lines in a file. Words are separated by whitespace characters. The file name should be passed as a command-line argument, as shown below. c:\exercise>java Exercise12_13 Loan.java File loan.java has 1919 characters 210 words 71 lines c:\exercise> Class Name: Exercise12_13
write mips assembly mips assembly (x+a) (bx^2+cx+d) using the pesedo- code with loop ,program should claclute...
write mips assembly mips assembly (x+a) (bx^2+cx+d) using the pesedo- code with loop ,program should claclute six T[i] and display aproper message about roots .the the program should store all T[i] as memory array a = [1, 1, 1, 1, 1, 1]; b = [1, 2, 4, 8, 16, 32]; c = [-6, -4, -2, 2, 4, 6]; d = [-1, -3, -5, -7, -9, -11]; for (i=0 ; i<=6; i++) { T[i] =-4 *b [i] * d[i] +c[i] *...
Using MARS and MIPS 2. Write and test a program to swap the contents of two...
Using MARS and MIPS 2. Write and test a program to swap the contents of two registers. Assume there is only one additional register available that may be destroyed. Your program should initially read values (of type integer, float or string) into registers. Next, it will swap the values read, then print the final contents of each register (you are not allowed to use "move").
Use MIPS write an assembly program which asks the user to enter 3 number. The program...
Use MIPS write an assembly program which asks the user to enter 3 number. The program then sorts these numbers, the prints them from largest to smallest.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT