Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can anyone help me convert this C++ code into MIPS assembly? Please, and thank y

ID: 3801936 • Letter: C

Question

Can anyone help me convert this C++ code into MIPS assembly? Please, and thank you!

-

-

Description: For this 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 modifications to the assembly file. 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 expressions 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:
Sum: 5050
Reversed Number: 98654
is Palindrome: 1

-
Submission: .s file

-

-

-

-

In other words, you will be converting the C++ code file p4code.cpp into MIPS assembly!

Base M Code data a sci iz "An" used for cout endl endl a SC11 z "Sum: label for sum sumalbl a SC11 z Reversed Number label for rev revlbl a SC11 z Is Palindrome label for is Palindrome pallbl word 1 arr word 2 word 3 word 4 word 5 100 word 4 11 word 3 12 word 2 13 word 1 14 text 15 16 17 Sum 18 rev 19 num is Palin drome 20 address of arr SS4 21 22 beg 23 end 24 25 10 26 100 27 main. exit 30 31 la $a0 sumalbl puts sumalbl into arg0 (a0 register) for cout addi $v0, $0 4 puts 4 in v0 which denotes we are printing a 32 string 33 sys call make a sys call to system $a0, $s0 argo (a0 register) for puts sum into cout 35 move 36 addi 0, $0, 1 puts 1 in v0 to denote we are printing an int 37 sys call make a sys call to system $a0 la endl puts the address of the string endl into a0 40 addi Sv0, $0, 4 puts 4 into VU saying we are printing a string 41 sys call 42 43 la $a0 re l bl puts rev lbl into arg0 (a0 register) for cout addi 0, $0, 4 puts 4 in v0 which denotes we are printing an 44 string 45 sys call make a sys call to system 46 47 puts rev into arg 48 addi 0, $0, 1 puts 1 in v0 to denote we are printing an int

Explanation / Answer

.LC1:
.ascii "sum"
.LC2:
.ascii "reverse no"
.LC3:
.ascii "ispalindrome"
.LC0:
.word 1
.word 2
.word 3
.word 4
.word 5
.word 4
.word 3
.word 2
.word 1
main:
daddiu $sp,$sp,-112
sd $31,104($sp)
sd $fp,96($sp)
sd $28,88($sp)
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(main)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(main)))
ld $2,%got_disp(__stack_chk_guard)($28)
ld $2,0($2)
sd $2,72($fp)
sw $0,0($fp)
li $2,1 # 0x1
sw $2,4($fp)
.L3:
lw $2,4($fp)
slt $2,$2,101
beq $2,$0,.L2
nop

lw $3,0($fp)
lw $2,4($fp)
addu $2,$3,$2
sw $2,0($fp)
lw $2,4($fp)
addiu $2,$2,1
sw $2,4($fp)
b .L3
nop

.L2:
li $2,45689 # 0xb279
sw $2,8($fp)
sw $0,12($fp)
li $2,-1 # 0xffffffffffffffff
sw $2,28($fp)
.L5:
lw $2,8($fp)
blez $2,.L4
nop

lw $4,8($fp)
move $5,$4
move $3,$5
dsll $2,$3,1
move $3,$2
dsll $2,$3,2
dsubu $2,$2,$3
dsll $3,$2,4
daddu $2,$2,$3
dsll $3,$2,8
daddu $2,$2,$3
dsll $3,$2,16
daddu $2,$2,$3
daddu $2,$2,$5
dsrl $2,$2,32
sll $2,$2,0
sra $3,$2,2
sra $2,$4,31
subu $2,$3,$2
sll $2,$2,1
sll $3,$2,2
addu $2,$2,$3
subu $2,$4,$2
sw $2,28($fp)
lw $2,12($fp)
sll $2,$2,1
sll $3,$2,2
addu $2,$2,$3
lw $3,28($fp)
addu $2,$3,$2
sw $2,12($fp)
lw $5,8($fp)
move $4,$5
move $3,$4
dsll $2,$3,1
move $3,$2
dsll $2,$3,2
dsubu $2,$2,$3
dsll $3,$2,4
daddu $2,$2,$3
dsll $3,$2,8
daddu $2,$2,$3
dsll $3,$2,16
daddu $2,$2,$3
daddu $2,$2,$4
dsrl $2,$2,32
sll $2,$2,0
sra $3,$2,2
sra $2,$5,31
subu $2,$3,$2
sw $2,8($fp)
b .L5
nop

.L4:
ld $2,%got_page(.LC0)($28)
daddiu $3,$2,%got_ofst(.LC0)
ldl $4,%got_ofst(.LC0)($2)
ldr $4,7($3)
move $6,$4
daddiu $3,$2,%got_ofst(.LC0)
ldl $4,8($3)
ldr $4,15($3)
move $5,$4
daddiu $3,$2,%got_ofst(.LC0)
ldl $4,16($3)
ldr $4,23($3)
daddiu $3,$2,%got_ofst(.LC0)
ldl $7,24($3)
ldr $7,31($3)
move $3,$7
sd $6,32($fp)
sd $5,40($fp)
sd $4,48($fp)
sd $3,56($fp)
daddiu $2,$2,%got_ofst(.LC0)
lw $2,32($2)
sw $2,64($fp)
sw $0,16($fp)
li $2,8 # 0x8
sw $2,20($fp)
li $2,1 # 0x1
sw $2,24($fp)
.L8:
lw $3,16($fp)
lw $2,20($fp)
slt $2,$3,$2
beq $2,$0,.L6
nop

lw $2,16($fp)
dsll $2,$2,2
daddiu $3,$fp,80
daddu $2,$3,$2
lw $3,-48($2)
lw $2,20($fp)
dsll $2,$2,2
daddiu $4,$fp,80
daddu $2,$4,$2
lw $2,-48($2)
beq $3,$2,.L7
nop

li $2,-1 # 0xffffffffffffffff
sw $2,24($fp)
b .L6
nop

.L7:
lw $2,16($fp)
addiu $2,$2,1
sw $2,16($fp)
lw $2,20($fp)
addiu $2,$2,-1
sw $2,20($fp)
b .L8
nop

.L6:
ld $2,%got_page(.LC1)($28)
daddiu $5,$2,%got_ofst(.LC1)
ld $4,%got_disp(std::cout)($28)
ld $2,%call16(std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*))($28)
move $25,$2
1: jalr $25
nop

move $3,$2
lw $2,0($fp)
move $5,$2
move $4,$3
ld $2,%call16(std::basic_ostream<char, std::char_traits<char> >::operator<<(int))($28)
move $25,$2
1: jalr $25
nop

ld $5,%got_disp(std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&))($28)
move $4,$2
ld $2,%call16(std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&)))($28)
move $25,$2
1: jalr $25
nop

ld $2,%got_page(.LC2)($28)
daddiu $5,$2,%got_ofst(.LC2)
ld $4,%got_disp(std::cout)($28)
ld $2,%call16(std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*))($28)
move $25,$2
1: jalr $25
nop

move $3,$2
lw $2,12($fp)
move $5,$2
move $4,$3
ld $2,%call16(std::basic_ostream<char, std::char_traits<char> >::operator<<(int))($28)
move $25,$2
1: jalr $25
nop

ld $5,%got_disp(std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&))($28)
move $4,$2
ld $2,%call16(std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&)))($28)
move $25,$2
1: jalr $25
nop

ld $2,%got_page(.LC3)($28)
daddiu $5,$2,%got_ofst(.LC3)
ld $4,%got_disp(std::cout)($28)
ld $2,%call16(std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*))($28)
move $25,$2
1: jalr $25
nop

move $3,$2
lw $2,24($fp)
move $5,$2
move $4,$3
ld $2,%call16(std::basic_ostream<char, std::char_traits<char> >::operator<<(int))($28)
move $25,$2
1: jalr $25
nop

ld $5,%got_disp(std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&))($28)
move $4,$2
ld $2,%call16(std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&)))($28)
move $25,$2
1: jalr $25
nop

move $2,$0
ld $3,%got_disp(__stack_chk_guard)($28)
ld $4,72($fp)
ld $3,0($3)
beq $4,$3,.L10
nop

ld $2,%call16(__stack_chk_fail)($28)
move $25,$2
1: jalr $25
nop

.L10:
move $sp,$fp
ld $31,104($sp)
ld $fp,96($sp)
ld $28,88($sp)
daddiu $sp,$sp,112
j $31
nop

__static_initialization_and_destruction_0(int, int):
daddiu $sp,$sp,-48
sd $31,40($sp)
sd $fp,32($sp)
sd $28,24($sp)
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(__static_initialization_and_destruction_0(int, int))))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(__static_initialization_and_destruction_0(int, int))))
move $3,$4
move $2,$5
sll $3,$3,0
sw $3,12($fp)
sll $2,$2,0
sw $2,8($fp)
lw $3,12($fp)
li $2,1 # 0x1
bne $3,$2,.L13
nop

lw $3,8($fp)
li $2,65535 # 0xffff
bne $3,$2,.L13
nop

ld $2,%got_page(std::__ioinit)($28)
daddiu $4,$2,%got_ofst(std::__ioinit)
ld $2,%call16(std::ios_base::Init::Init())($28)
move $25,$2
1: jalr $25
nop

ld $6,%got_disp(__dso_handle)($28)
ld $2,%got_page(std::__ioinit)($28)
daddiu $5,$2,%got_ofst(std::__ioinit)
ld $4,%got_disp(std::ios_base::Init::~Init())($28)
ld $2,%call16(__cxa_atexit)($28)
move $25,$2
1: jalr $25
nop

.L13:
nop
move $sp,$fp
ld $31,40($sp)
ld $fp,32($sp)
ld $28,24($sp)
daddiu $sp,$sp,48
j $31
nop

_GLOBAL__sub_I_main:
daddiu $sp,$sp,-32
sd $31,24($sp)
sd $fp,16($sp)
sd $28,8($sp)
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(_GLOBAL__sub_I_main)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(_GLOBAL__sub_I_main)))
li $5,65535 # 0xffff
li $4,1 # 0x1
ld $2,%got_page(__static_initialization_and_destruction_0(int, int))($28)
daddiu $2,$2,%got_ofst(__static_initialization_and_destruction_0(int, int))
move $25,$2
1: jalr $25
nop

move $sp,$fp
ld $31,24($sp)
ld $fp,16($sp)
ld $28,8($sp)
daddiu $sp,$sp,32
j $31
nop

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote