Convert the following C Language program to ARM assembly lan

Convert the following C Language program to ARM assembly language program by hand coding. The program essentially computes n! (n-factorial) value using the recursive function call technique.

The ARM assembly program should work on the KEIL simulator and give the correct result for any reasonable ‘n’ value.

Note: Assign ‘n’ to R0 and ‘result’ to R5

C program below

#include <stdio.h>

   long int multipyNumbers(int n);

int main()

{

int n=5;

int resutlt = 0xFFFFAAAA;

result = multiplyNumber(n);

return 0;

}

long int multiplyNumber( int n )

{

if (n>=1)

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

else

return1

}

Solution

.Ltext0:
        .globl   main
    main:
    .LFB0:
        .cfi_startproc
       pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
       movq   %rsp, %rbp
        .cfi_def_cfa_register 6
       subq   $16, %rsp
       movl   $5, -8(%rbp)
  
       movl   $-21846, -4(%rbp)

       movl   -8(%rbp), %eax
       movl   %eax, %edi
        call   multiplynumber

        movl   %eax, -4(%rbp)
        movl   $0, %eax
  
        leave
        .cfi_def_cfa 7, 8
       ret
        .cfi_endproc
    .LFE0:
        .globl   multiplynumber
    multiplynumber:
    .LFB1:
        .cfi_startproc
       pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
       movq   %rsp, %rbp
        .cfi_def_cfa_register 6
       subq   $16, %rsp
        movl   %edi, -4(%rbp)
        cmpl   $0, -4(%rbp)
        jle   .L4
    .LBB2:
        movl   -4(%rbp), %eax
        subl   $1, %eax
        movl   %eax, %edi
       movl   $0, %eax

       call   multiplynumbers
   imull   -4(%rbp), %eax
       cltq
       jmp   .L5
    .L4:
    .LBE2:
       movl   $1, %eax

    .L5:
        leave
   .cfi_def_cfa 7, 8
       ret
        .cfi_endproc
    .LFE1:
    .Letext0:

Convert the following C Language program to ARM assembly language program by hand coding. The program essentially computes n! (n-factorial) value using the recu
Convert the following C Language program to ARM assembly language program by hand coding. The program essentially computes n! (n-factorial) value using the recu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site