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

Convert to MIPS : Using the given register names : just need main conversion onl

ID: 3801669 • Letter: C

Question

Convert to MIPS : Using the given register names : just need main conversion only nothing else .....

# sum --> $s0

# rev --> $s1

# num --> $s2

# isPalindrome --> $s3

# address of arr --> $s4

# i --> $s5

# beg --> $s6

# end --> $s7

# d --> $t0

# 10 --> $t1

# 100 --> $t3

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

MIPS : Given coding which already has printing coding so only need to fill the main area using listed register name

.data

endl: .asciiz " " # used for cout << endl;

sumlbl: .asciiz "Sum: " # label for sum

revlbl: .asciiz "Reversed Number: " # label for rev

pallbl: .asciiz "Is Palindrome: " # label for isPalindrome

arr: .word 1

   .word 2

   .word 3

   .word 4

   .word 5

   .word 4

   .word 3

   .word 2

   .word 1

.text

main:

fill only this part ......

exit:

la $a0, sumlbl # puts sumlbl 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 sum 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, revlbl # puts revlbl 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 rev 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, pallbl # puts pallbl 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 isPalindrome 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

Given C ++ Coding : Please use given register name listed above

Explanation / Answer

.LC0:
.string "Sum: "
.LC1:
.string "Reversed Number: "
.LC2:
.string "Is Palindrome: "
main:
push rbp
mov rbp, rsp
sub rsp, 80
mov DWORD PTR [rbp-4], 0
mov DWORD PTR [rbp-8], 1
.L3:
cmp DWORD PTR [rbp-8], 100
jg .L2
mov eax, DWORD PTR [rbp-8]
add DWORD PTR [rbp-4], eax
add DWORD PTR [rbp-8], 1
jmp .L3
.L2:
mov DWORD PTR [rbp-12], 45689
mov DWORD PTR [rbp-16], 0
mov DWORD PTR [rbp-32], -1
.L5:
cmp DWORD PTR [rbp-12], 0
jle .L4
mov ecx, DWORD PTR [rbp-12]
mov edx, 1717986919
mov eax, ecx
imul edx
sar edx, 2
mov eax, ecx
sar eax, 31
sub edx, eax
mov eax, edx
sal eax, 2
add eax, edx
add eax, eax
sub ecx, eax
mov eax, ecx
mov DWORD PTR [rbp-32], eax
mov edx, DWORD PTR [rbp-16]
mov eax, edx
sal eax, 2
add eax, edx
add eax, eax
mov edx, eax
mov eax, DWORD PTR [rbp-32]
add eax, edx
mov DWORD PTR [rbp-16], eax
mov ecx, DWORD PTR [rbp-12]
mov edx, 1717986919
mov eax, ecx
imul edx
sar edx, 2
mov eax, ecx
sar eax, 31
sub edx, eax
mov eax, edx
mov DWORD PTR [rbp-12], eax
jmp .L5
.L4:
mov DWORD PTR [rbp-80], 1
mov DWORD PTR [rbp-76], 2
mov DWORD PTR [rbp-72], 3
mov DWORD PTR [rbp-68], 4
mov DWORD PTR [rbp-64], 5
mov DWORD PTR [rbp-60], 4
mov DWORD PTR [rbp-56], 3
mov DWORD PTR [rbp-52], 2
mov DWORD PTR [rbp-48], 1
mov DWORD PTR [rbp-20], 0
mov DWORD PTR [rbp-24], 8
mov DWORD PTR [rbp-28], 1
.L8:
mov eax, DWORD PTR [rbp-20]
cmp eax, DWORD PTR [rbp-24]
jge .L6
mov eax, DWORD PTR [rbp-20]
cdqe
mov edx, DWORD PTR [rbp-80+rax*4]
mov eax, DWORD PTR [rbp-24]
cdqe
mov eax, DWORD PTR [rbp-80+rax*4]
cmp edx, eax
je .L7
mov DWORD PTR [rbp-28], -1
jmp .L6
.L7:
add DWORD PTR [rbp-20], 1
sub DWORD PTR [rbp-24], 1
jmp .L8
.L6:
mov esi, OFFSET FLAT:.LC0
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
mov rdx, rax
mov eax, DWORD PTR [rbp-4]
mov esi, eax
mov rdi, rdx
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov esi, OFFSET FLAT:std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
mov rdi, rax
call 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> >&))
mov esi, OFFSET FLAT:.LC1
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
mov rdx, rax
mov eax, DWORD PTR [rbp-16]
mov esi, eax
mov rdi, rdx
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov esi, OFFSET FLAT:std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
mov rdi, rax
call 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> >&))
mov esi, OFFSET FLAT:.LC2
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
mov rdx, rax
mov eax, DWORD PTR [rbp-28]
mov esi, eax
mov rdi, rdx
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov esi, OFFSET FLAT:std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
mov rdi, rax
call 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> >&))
mov eax, 0
leave
ret
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L12
cmp DWORD PTR [rbp-8], 65535
jne .L12
mov edi, OFFSET FLAT:std::__ioinit
call std::ios_base::Init::Init()
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:std::__ioinit
mov edi, OFFSET FLAT:std::ios_base::Init::~Init()
call __cxa_atexit
.L12:
nop
leave
ret
_GLOBAL__sub_I_main:
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret