Question: I need to write the following map function c code into assembly specifically in NASM: void map ( int * A, int n, int (

I need to write the following map function c code into assembly specifically in NASM: void map(int *A, int n, int (*f)(int)) { for (int i=0; i < n; i++) A[i] = f(A[i]); } 

and so far what I've tried is below:

map: push ebp mov ebp, esp pusha mov ebx, [ebp+12] mov edx, [ebp+16]

forloop: mov ecx, [ebp+8] cmp dword [iter], ebx jz ifnotfound

mov eax, dword [iter] imul eax, 4 add ecx, eax cmp edx, dword [ecx] jz iffound

inc dword [iter] jmp forloop

iffound: mov dword [returnf], ecx jmp endforloop

ifnotfound: mov dword [returnf], 0d

endforloop: mov dword [iter], 0d popa mov eax, dword [returnf] pop ebp ret

but it doesn't seem matching with the c code above. Need help to fix or rewrite into correct answer.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!