Question
C++ Computer Architecture Assignment (Files Provided) Use MARS 4.5 Topics tested: Compiling C++ to Mips Decompiling Mips into C++/Python (MIPS) For the following C statement,
C++ Computer Architecture Assignment (Files Provided)
Use MARS 4.5
Topics tested:
Compiling C++ to Mips
Decompiling Mips into C++/Python
(MIPS) For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively.
A[0] = B[0] + B[1] + B[2]; A[1] = f + g; A[2] = i - h;
(C++) Manually decompile the following MIPS code to C++ (or Python). Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively.
add $s2, $s2, $s3 addi $s2, $s2, 2 sw $s2, ($s7) addi $s2, $s2, 2 sw $s2, 4($s7) addi $s2, $s2, 2 sw $s2, 8($s7) addi $s2, $s2, 2 sw $s2, 12($s7) addi $s2, $s2, 2 sw $s2, 16($s7) addi $s2, $s2, 2
ASM file
# Code by {Your name here} #By the way, any text followed by a "#" is a comment #Data section of the MIPS assembly .data # Create a label of A with an allocation of 40 bytes (enough for an array of 10 words) A: .space 40 # Create a label of B with a list of integers (ie array) B: .word 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 #Mips code starts .text addi $s0, $0, 5 #f addi $s1, $0, 10 #g addi $s2, $0, 15 #h addi $s3, $0, 20 #i addi $s4, $0, 3 #j #The following is called a pseudo instruction, it really asssembles into TWO instructions #What what happens when you execute it #Get the address of the variable A and put it in register s6 la $s6, A #Get the address of the variable B and put it in register s7 la $s7, B #DO NOT REMOVE THIS COMMENT - Your code BELOW #DO NOT REMOVE THIS COMMENT - Your code ABOVE #This is a exit label, if we do not do the following two lines you will see a message about falling of the bottom #The next two lines are the equivalent of return 0 in C++ #I will never require the syscall functions on an quiz or exam exit: addi $v0, $0, 10 # system call for exit syscall # we are out of here.
C++ File
//Your name here #include #include int main() { int f, g, h, i, j; int A[] = {2, 4, 8, 10, 12, 14, 16, 18, 20, 22}; int B[] = {0, 2, 1, 3, 2, 1, 3, 4, 6, 5}; f = 2; g = 5; h = 6; i = 3; j = 8; //DO NOT REMOVE THIS COMMENT - Your code BELOW //DO NOT REMOVE THIS COMMENT - Your code ABOVE for ( size_t i = 0 ; i < sizeof(A)/sizeof(int) ; ++i ) std::cout << "A[" << i << "] = " << A[i] << std::endl; for ( size_t i = 0 ; i < sizeof(A)/sizeof(int) ; ++i ) std::cout << "B[" << i << "] = " << B[i] << std::endl; std::cout << "f = " << f << std::endl; std::cout << "g = " << g << std::endl; std::cout << "h = " << h << std::endl; std::cout << "i = " << i << std::endl; std::cout << "j = " << j << std::endl; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started