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

Write an assembly program to find the largest element by searching an array. Use

ID: 3811606 • Letter: W

Question

Write an assembly program to find the largest element by searching an array. Use cmp instruction and the appropriate jump instruction (signed or unsigned) to translate the if and while statements. Use $ operator to calculate the size of the array, and inc instruction to incremenet the index of the array.

int ary[] = {1,5,-3,-4,0,6,11,-9,18}
int index = 0;
int max = ary[0];
int arraySize = sizeof array / sizeof max
   while (index < arraySize)
{
if (ary[index < arraySize)
   max = ary[index];
}







Explanation / Answer

Assembly language proram'

main:
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-48], 1
mov DWORD PTR [rbp-44], 5
mov DWORD PTR [rbp-40], -3
mov DWORD PTR [rbp-36], -4
mov DWORD PTR [rbp-32], 0
mov DWORD PTR [rbp-28], 6
mov DWORD PTR [rbp-24], 11
mov DWORD PTR [rbp-20], -9
mov DWORD PTR [rbp-16], 18
mov DWORD PTR [rbp-4], 0
mov eax, DWORD PTR [rbp-48]
mov DWORD PTR [rbp-8], eax
mov DWORD PTR [rbp-12], 9
.L4:
mov eax, DWORD PTR [rbp-4]
cmp eax, DWORD PTR [rbp-12]
jge .L2
mov eax, DWORD PTR [rbp-4]
cdqe
mov eax, DWORD PTR [rbp-48+rax*4]
cmp eax, DWORD PTR [rbp-12]
jge .L3
mov eax, DWORD PTR [rbp-4]
cdqe
mov eax, DWORD PTR [rbp-48+rax*4]
mov DWORD PTR [rbp-8], eax
.L3:
add DWORD PTR [rbp-4], 1
jmp .L4
.L2:
mov eax, 0
pop rbp
ret

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote