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

Convert the following C Language program to ARM assembly language program by han

ID: 3777528 • Letter: C

Question

Convert the following C Language program to ARM assembly language program by hand coding. The program essentially adds a fix value, 4, to every element of the array. The last value in the array is 0 and it must not be changed

The ARM assembly program should work on the KEIL simulator and give the correct result for any array.

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

Convert C to Assembly Register assignments: assign arrayPtr to R0. ( You may use temporary registers as you see fit)

C Program:

int * myArray = {23,54,32,11,71,45,68,99,0};

main()

{

int * arrayPtr = NULL;

arrayPtr = myArray;

while(*arrayPtr != 0)

{

*arrayPtr = *arrayPtr + 4;

arrayPtr++;

}

}

Please help

Explanation / Answer

Answer:

Assembly Language Code :

.zero 1
main:
push rbp
mov rbp, rsp
lea rdx, [rbp-96]
mov eax, 0
mov ecx, 10
mov rdi, rdx
rep stosq
mov DWORD PTR [rbp-96], 23
mov DWORD PTR [rbp-92], 54
mov DWORD PTR [rbp-88], 32
mov DWORD PTR [rbp-84], 11
mov DWORD PTR [rbp-80], 71
mov DWORD PTR [rbp-76], 45
mov DWORD PTR [rbp-72], 68
mov DWORD PTR [rbp-68], 99
mov QWORD PTR [rbp-8], 0
lea rax, [rbp-96]
mov QWORD PTR [rbp-8], rax
.L3:
mov rax, QWORD PTR [rbp-8]
mov eax, DWORD PTR [rax]
test eax, eax
je .L2
mov rax, QWORD PTR [rbp-8]
mov eax, DWORD PTR [rax]
lea edx, [rax+4]
mov rax, QWORD PTR [rbp-8]
mov DWORD PTR [rax], edx
add QWORD PTR [rbp-8], 4
jmp .L3
.L2:
mov eax, 0
pop rbp
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 .L7
cmp DWORD PTR [rbp-8], 65535
jne .L7
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
.L7:
nop
leave
ret
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret