Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have to translate C++ code into MIPS. It is expected to have an output of: Value of a: 25 Value of b: 31 Value

I have to translate C++ code into MIPS. It is expected to have an output of: Value of a: 25 Value of b: 31 Value of c: 18 Value of d: 49

Here is the C++ code:

I need to translate this C++ into MIPS code.

#include using namespace std; int main(void) { int a = 5; int b = 6; int c = 7; int d; d = -1; if ( a < 10){ a++; }else{ a--; } d = a + c; c = a + d; if( b < 10 ) { b++; c--; }else{ b--; c++; } a = c + b; b = c + d; if(b < c && b > a){ d = a + b; }else if (b > c || c < a){ d = b + c; } cout << "Value of a: " << a << endl; cout << "Value of b: " << b << endl; cout << "Value of c: " << c << endl; cout << "Value of d: " << d << endl; return 0; } 

Here is what was give.

.data endl: .asciiz " " # used for cout << endl; albl: .asciiz "Value of a: " # label for a blbl: .asciiz "Value of b: " # label for b clbl: .asciiz "Value of c: " # label for c dlbl: .asciiz "Value of d: " # label for d .text

# a --> $s0 # b --> $s1 # c --> $s2 # d --> $s3 main:

(fill in here)

exit: la $a0, albl # puts albl into arg0 (a0 register) for cout addi $v0, $0, 4 # puts 4 in v0 which denotes we are printing a string syscall # make a syscall to system move $a0, $s0 # puts a into arg0 (a0 register) for cout addi $v0, $0, 1 # puts 1 in v0 to denote we are printing an int syscall # make a syscall to system

la $a0, endl # puts the address of the string endl into a0 addi $v0, $0, 4 # puts 4 into v0 saying we are printing a string syscall

la $a0, blbl # puts blbl into arg0 (a0 register) for cout addi $v0, $0, 4 # puts 4 in v0 which denotes we are printing an string syscall # make a syscall to system move $a0, $s1 # puts b into arg0 (a0 register) for cout addi $v0, $0, 1 # puts 1 in v0 to denote we are printing an int syscall # make a syscall to system

la $a0, endl # puts the address of the string endl into a0 addi $v0, $0, 4 # puts 4 into v0 saying we are printing a string syscall

la $a0, clbl # puts clbl into arg0 (a0 register) for cout addi $v0, $0, 4 # puts 4 in v0 which denotes we are printing a string syscall # make a syscall to system move $a0, $s2 # puts c into arg0 (a0 register) for cout addi $v0, $0, 1 # puts 1 in v0 to denote we are printing an int syscall # make a syscall to system

la $a0, endl # puts the address of the string endl into a0 addi $v0, $0, 4 # puts 4 into v0 saying we are printing a string syscall

la $a0, dlbl # puts dlbl into arg0 (a0 register) for cout addi $v0, $0, 4 # puts 4 in v0 which denotes we are printing a string syscall # make a syscall to system move $a0, $s3 # puts d into arg0 (a0 register) for cout addi $v0, $0, 1 # puts 1 in v0 to denote we are printing an int syscall # make a syscall to system

la $a0, endl # puts the address of the string endl into a0 addi $v0, $0, 4 # puts 4 into v0 saying we are printing a string syscall addi $v0,$0, 10 syscall

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

=+8. Why is productivity important?

Answered: 1 week ago

Question

=+ 9. What is inflation and what causes it?

Answered: 1 week ago

Question

=+6. What does the invisible hand of the marketplace do?

Answered: 1 week ago