Question: Assembly Language Assume that we execute function hw2 with the following inputs: arr1 = {20, 43, 45, 5, 7, 76, 234, 56, 6, 8}; len

Assembly Language

Assume that we execute function hw2 with the following inputs:

arr1 = {20, 43, 45, 5, 7, 76, 234, 56, 6, 8};

len = 10;

Answer the following questions:

(i) Show the content of the registers (ESI, EDI, ECX) right after the instruction in line 5 is executed.

(ii) Show the content of the registers (EAX, EBX, EDX) right after the 5th execution of the instruction in line 15.

(iii) Show the content of the registers (EAX, EBX, EDX) right after the 8th execution of the instruction in line 15.

(iv) Show the content of the registers (EAX, EBX, ECX, EDX) in line 17.

(v) Briefly describe what this function computes.

Notes:

You may represent values in decimal or hexadecimal.

Denote the base address of array by &arr1.

int hw2(int *arr1, int len)

{

int ret_val;

__asm{

1 mov esi, arr1

2 mov edi, 0

3 mov ecx, len

4 mov edx, 0

5 mov ebx, 0

6 WHILE:

7 cmp ebx, len

8 jge WHILE_END

9 mov eax, dword ptr[esi+4*ebx]

10 and eax, 1

11 cmp eax, 1

12 jne INCREMENT_INDEX

13 inc edx

14 INCREMENT_INDEX:

15 inc ebx

16 jmp WHILE

17 WHILE_END:

18 mov eax, edx

19 mov ret_val, eax

}

return ret_val;

}

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!