Question: Write a program in both MIPS assembly language or C++ that reads its own instructions and counts the number of occurrences of each type of

Write a program in both MIPS assembly language or C++ that reads its own instructions and counts the number of occurrences of each type of instruction (R-type, I-type, or J-type). To accomplish this task, your program should execute the following steps:

  1. First, your program should load the address of its first instruction (0x400000) into a register, and initialize three separate instruction class counters to zero.
  2. Next, your program should enter a loop that reads each instruction from memory. For each instruction, examine the op code field to determine whether it is an R-type, I-type, or J-type instruction, and increment the appropriate instruction class counter. (For the purpose of this assignment, you may assume that all instructions with an op code of 0 are R-type instructions; all instructions with an op code equal to either 2 or 3 are J-type instructions; and all other instructions are I-type instructions.)
  3. Your source programs final two instructions should be

li $v0, 10

syscall

Thus, your program should repeat step 2s loop until the machine instructions corresponding to this sequence are detected. (Be sure to count these machine instructions as well!)

  1. Finally, save the values of your instruction class counters to variables declared in the data segment of your program. (For testing purposes, I recommend also using syscalls to display the three integer counts to the screen; if you do, be careful not to halt on these additional syscall instructions.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!