Question
Need to translate this C++ code into MIPS Assembly Description For project, your objective is to convert the given C++ code into MIPS assembly. Please
Need to translate this C++ code into MIPS Assembly
Description For project, your objective is to convert the given C++ code into
MIPS assembly. Please do not modify the C++ code itself. You are only allowed to
make modications to the assembly code. Start writing your code below the main: label
and above the exit: label. For this project stay BETWEEN these labels.
When doing a C++ to MIPS conversion, it can be done in the following steps:
1 Assign variables to registers. When inspecting code, any constant values in ex-
pressions may need to be assigned to temporary registers.
2 Initialize variables to registers. (actually put the values into the registers.)
3 Then move onto the rest of the code.
Expected Output:
String: dlrow laer eht ot emoclew
C++ code:
#include
using namespace std;
int main(void) {
char string[] = "welcome to the real world"; int beg; int end;
beg = 0; end = 24; char temp; while(beg < end){ temp = string[beg]; string[beg] = string[end]; string[end] = temp; beg = beg + 1; end = end - 1; }
printf("String : %s ", string ); }
MIPS Base code.
.data
endl: .asciiz " " # used for cout << endl;
label: .asciiz "String: "
string: .byte 'w','e','l','c','o','m','e',' ', 't','o',' ','t', 'h','e',' ', 'r','e','a','l',' ','w','o','r','l','d'
.text
# addr of string --> $s0
# beg --> $s1
# end --> $s2
# temp --> $s3
main:
exit:
la $a0, label # puts label 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 address of string into arg0 (a0 register) for cout
addi $v0, $0, 4 # puts 4 in v0 to denote we are printing a String
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
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