MIPS Simulator QtSpim: You are to have a complete program in MIPS assembly language that behaves exactly as the included C program. This program contains four functions in addition to the main() one. Your solution must contain all five C routines as they have been coded in the example. Make sure to run the program in MIPS and show the same output on MIPS as well to make sure there are no errors. Below is the five C routines and attached is the image of what the output must print out on QtSpim.
#include <stdio.h>
int getMax(int arr[], int n)
{
int mx = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > mx)
mx = arr[i];
return mx;
}
void countSort(int arr[], int n, int exp)
{
int output[n];
int i, count[10] = { 0 };
for (i = 0; i < n; i++)
count[(arr[i] / exp) % 10]++;
for (i = 1; i < 10; i++)
count[i] += count[i - 1];
for (i = n - 1; i >= 0; i--) {
output[count[(arr[i] / exp) % 10] - 1] = arr[i];
count[(arr[i] / exp) % 10]--;
}
for (i = 0; i < n; i++)
arr[i] = output[i];
}
void radixSort(int arr[], int n)
{
int m = getMax(arr, n);
for (int exp = 1; m / exp > 0; exp *= 10)
countSort(arr, n, exp);
}
void printData(int arr[], int n)
{
for (int i = 0; i < n; i++)
printf("%d \n", arr[i]);
}
int main()
{
int arr[] = {7, 9, 4, 3, 8, 1, 6, 2, 5};
int n = sizeof(arr) / sizeof(arr[0]);
radixSort(arr, n);
printData(arr, n);
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
I got errors when I ran the code above. The tutor simply just pasted the image I posted. I need the actual code for MIPS that prints out the eact same output as it would print out in C. Give me the actual code for MIPS.
I got errors when I ran the code above. The tutor simply just pasted the image I posted. I need the actual code for MIPS that prints out the eact same output as it would print out in C. Give me the actual code for MIPS.
- The following instruction set is supported by a simple processor, which is similar to what we discussed in the class, with a few new instructions added. The format of most instructions is defined as follows. bits 15:14 13:10 9 8:6 5:3 2:0 field unused opcode w srcl src2 dst where the fields are defined as follows. opcode : operation to be performed by the processor write back ALU output to register file (1= yes, 0 = no) address of the first ALU operand in the register file address of the second ALU operand in the register file address in the register file where the output is written w: srcl: src2: dst: For opcodes BEQ, BLEZ and JUMP, the 6 least significant bits (5:0) give an address in the instruction memory, which is byte-addressed. The opcode HALT has all operand bits (9:0) being 0. When an instruction has only two operands, the field for the unused operand is filled with 0-bits. For example, bits (5:3) for SLL are all zero because src2 is not used. The opcode and meaning of these…arrow_forwardIN C ONLYarrow_forwardWHats the pseduo code in c++/python for number 2?arrow_forward
- Consider the following C code: 1: int main() { 2: 3: 4: 5: } int y = 5; // Return y times 4 return y* 4; What is removed during the preprocessing step of compilation? A. Line 1 B. Line 3 C. Line 5 D. Lines 3 and 5 E. Everything, since it will be assembly after the preprocessing steparrow_forwardWrite a code in sim8085 for the following problem: The pressure of two boilers is monitored and controlled by a microcomputer works based on microprocessor programming. A set of 6 readings of first boiler, recorded by six pressure sensors, which are stored in the memory location starting from 2050H. A corresponding set of 6 reading from the second boiler is stored at the memory location starting from 2060H. Each reading from the first set is expected to be higher than the corresponding position in the second set of readings. Write an 8085 sequence to check whether the first set of reading is higher than the second one or not. If all the readings of first set is higher than the second set, store 00 in the ‘D’ register. If any one of the readings is lower than the corresponding reading of second set, stop the process and store FF in the register ‘D’. Data (H): First set: 78, 89, 6A, 80, 90, 85 Second Set:71, 78, 65, 89, 56, 75arrow_forwardInstruction: Answer question 4 (a,b & c) only (1) Create a C++ project for your assignment 3, with the name format prescribed in the Information section. Add a source file and name it SwapCount. In this file, write the C++ program that will perform the tasks specified in question 2.(2) Declare and implement a function called sortSwapCount that passes three parameters, the array, the size and the reference of proportion, and returns the count. The functiondeclaration is int sortSwapCount(int data[], int size, double& proportion) (i) The function sorts the integers in data[] in ascending order using the bubble sort method. The purpose is to count or determine the number of exchanges (swaps) made by the bubble sort algorithm. (ii) The expected number of sorting swaps (expectedSwapCount) is size * (size - 1) if the array was unsorted. Calculate the proportion of the array status by first converting (or casting) the integers, swapCount and expectedSwapCount into floating-point,…arrow_forward
- For this homework assignment you are not allowed to use::MOVSB, MOVSW, MOVSD, CMPSB,CMPSW,CMPD,SCASB, SCASW, SCASD,STOSB, STOSW, STOSD, LODSB, LODSW, and LODSD. It is required that for each question write only one procedure that does the requested job. Only write the assembly part and avoid using directives. DO NOT USE IRVINE'S LIBRARY. Write a general-purpose program (only assembly code and no procedure call) that inserts a source string to the beginning of a target string. Sufficient space must exist in the target string to accommodate the new characters. Here is a sample call:.datatargetStr BYTE "Stanford",30 DUP(0)sourceStr BYTE "Kamran ",0.codearrow_forwardWrite the Mnemonics of the code and show the output in SIM8085arrow_forwardC++ and pseudocodearrow_forward
- Example: The Problem Input File Using C programming language write a program that simulates a variant of the Tiny Machine Architecture. In this implementation memory (RAM) is split into Instruction Memory (IM) and Data Memory (DM). Your code must implement the basic instruction set architecture (ISA) of the Tiny Machine Architecture: //IN 5 //OUT 7 //STORE O //IN 5 //OUT 7 //STORE 1 //LOAD O //SUB 1 55 67 30 55 67 1 LOAD 2- ADD 3> STORE 4> SUB 5> IN 6> OUT 7> END 8> JMP 9> SKIPZ 31 10 41 30 //STORE O 67 //OUT 7 11 /LOAD 1 //OUT 7 //END 67 70 Output Specifications Each piece of the architecture must be accurately represented in your code (Instruction Register, Program Counter, Memory Address Registers, Instruction Memory, Data Memory, Memory Data Registers, and Accumulator). Data Memory will be represented by an integer array. Your Program Counter will begin pointing to the first instruction of the program. Your simulator should provide output according to the input file. Along with…arrow_forwardPLEASE READ MY NOTE FIRST. Note: The following are the contents of a flex file that will be used to implement a lexical analyzer for a subset of the C programming language. I cannot understand anything in the code given below, so I need your help. I need you to explain every section of the code to me step-by-step in detail. At the end, please summarize what the code is all about and how it is functioning. Here's the code from the Flex file: %option noyywrap %{ #include<bits/stdc++.h> using namespace std; ofstream yyoutlog; //output filestream for log file string loglist = ""; //list of tokens along with line numbers // define necessary c++ variables and functions here (if any) int lines = 1; %} /* Regular Definitions */ delim [ \t\v\r] /* write regular expressions for whitespace and newline */ ws newline letter_ [A-Za-z_] digit [0-9] /* write regular expressions for id, float and integers */ id %% {ws} { /* ignore whitespace */ } {newline} {…arrow_forwardIn c++ write VM translator in which it will read a program written in HACK vm from an external file and ultimatley translate each line of code into Hack asm (assembly) , so, Higher level Hack Virtual machine language to Hack level assembly language. For example make it possible to translate the following: One Arithmetic (SUB), one logic (AND), and then Memory access command POP.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education