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

Convert the source code to ARM Assembly Code using ARM V Instruction Set int a =

ID: 3675375 • Letter: C

Question

Convert the source code to ARM Assembly Code using ARM V Instruction Set

int a = 5;

int const>

void main()

                int b = 30;

                int c = 75;

                int d;

                int array[1] = {7};

                d= a + b + c + one;

                array = new int [10];       //dynamically allocating size

                array[4] = d;

                array[8] = a;

                array[2] = c;

                                a = a + 15;

                if( a>0 )

                {

                                a=1;

                }

                else

                {

                                c = factorial( b );

                }

                for( int f=0; f<4; f=f+1; )

                {

                                a = a+1;

                                d = b + c;

                }

                d = factorial (a);               

int factorial(int n)

{

                if(n<1)

return 1;

else

return ( n * factorial(n-1) );

}

Explanation / Answer

// I have made some changes in the code because it was not getting compiled.

#include <iostream>
int a = 5;

int const>


int factorial(int n)

{

                if(n<1)

return 1;

else

return ( n * factorial(n-1) );

}

int main()

    {           int b = 30;

                int c = 75;

                int d;

              

                d= a + b + c + one;


                int *array;
              
                array = new int [10];       //dynamically allocating size
                array[1] = 7;

                array[4] = d;

                array[8] = a;

                array[2] = c;

                 a = a + 15;

                if( a>0 )

                {

                                a=1;

                }

                else

                {

                                c = factorial( b );

                }


                for( int f=0; f<4; f=f+1 )

                {

                                a = a+1;

                                d = b + c;

                }

                d = factorial (a);
                        return 0;

}

                      

// converted ARM Assembly Code

factorial(int):
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        subs    r3, r0, #0
        ble     .L4
        movs    r0, #1
.L3:
        mul     r0, r3, r0
        subs    r3, r3, #1
        bne     .L3
        bx      lr
.L4:
        movs    r0, #1
        bx      lr
main:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        push    {r3, r4, r5, lr}
        movw    r4, #:lower16:.LANCHOR0
        movt    r4, #:upper16:.LANCHOR0
        movs    r0, #40
        ldr     r5, [r4, #0]
        bl      operator new[](unsigned int)
        movs    r2, #7
        movs    r1, #75
        adds    r5, r5, #106
        mov     r3, r0
        movs    r0, #0
        str     r2, [r3, #4]
        str     r5, [r3, #16]
        ldr     r2, [r4, #0]
        str     r1, [r3, #8]
        str     r2, [r3, #32]
        ldr     r3, [r4, #0]
        adds    r3, r3, #15
        cmp     r3, #1
        it      ge
        movge   r3, #1
        adds    r3, r3, #4
        str     r3, [r4, #0]
        pop     {r3, r4, r5, pc}
global constructors keyed to a:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        push    {r4, lr}
        movw    r4, #:lower16:.LANCHOR1
        movt    r4, #:upper16:.LANCHOR1
        mov     r0, r4
        bl      std::ios_base::Init::Init()
        movw    r1, #:lower16:std::ios_base::Init::~Init()
        movw    r2, #:lower16:__dso_handle
        mov     r0, r4
        movt    r1, #:upper16:std::ios_base::Init::~Init()
        movt    r2, #:upper16:__dso_handle
        pop     {r4, lr}
        b       __aeabi_atexit
a:
        .word   5
std::__ioinit: