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

The following code is written in C++. Convert this code to MIPS32 assembly langu

ID: 672845 • Letter: T

Question

The following code is written in C++. Convert this code to MIPS32 assembly language. It can be assumed that the value that is entered by the user is a positive integer, int main() { int n; cout LT LT"Enter Integer cin GT GT n; cout LT LT"List Of Prime Integers Below "LT LT n LT LT endl; //Block of code that finds prime integer int prime = 1; for (int i=2; i LT n; i++) { prime = 1; for (int j=2; j*j LT =i; j++) { if (i % j == 0) { prime=0; break; //Exit this loop }} if( prime ==1) { cout LT LT i LT LT endl; } } //Exit the program return 0; }|

Explanation / Answer

MIPS code for given C++ code:

movl $.LC0, %edi
movl $0, %eax
call printf
leaq -16(%rbp), %rax
movq %rax, %rsi
movl $.LC1, %edi
movl $0, %eax
call __isoc99_scanf
movl $.LC2, %edi
movl $0, %eax
call printf
movl $1, -12(%rbp)
movl $2, -8(%rbp)
jmp .L2
movl $1, -12(%rbp)
movl $2, -4(%rbp)
jmp .L3
movl -8(%rbp), %eax
cltd
idivl -4(%rbp)
movl %edx, %eax
testl %eax, %eax
jne .L4
movl $0, -12(%rbp)
jmp .L5
addl $1, -4(%rbp)
.L4:
addl $1, -4(%rbp)
.L3:
movl -4(%rbp), %eax
imull -4(%rbp), %eax
cmpl -8(%rbp), %eax
jle .L6
.L5:
cmpl $1, -12(%rbp)
jne .L7
movl -8(%rbp), %eax
ovl %eax, %esi
movl $.LC1, %edi
movl $0, %eax
call printf
.L7:
addl $1, -8(%rbp)
.L2:
movl -16(%rbp), %eax
cmpl %eax, -8(%rbp)
jl .L8
movl $0, %eax

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