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

Write Y86 assembly code for a function that counts the number of elements in an

ID: 3938789 • Letter: W

Question

Write Y86 assembly code for a function that counts the number of elements in an array. See the following code for the set up:

.pos 0x400
.align 4
Array:
   .long 12
   .long -2
   .long 16
   .long -10
   .long 13
   .long -27
   .long 10
Done:

Output:
   .pos 0x500
   .align 4

Stack:
   .pos 0xF00
   .align 4

Main:
   irmovl $Stack, %ebp
   rrmovl %ebp, %esp
   irmovl $Array, %ecx
   irmovl $Output, %edx
#count

Define a function, called "count", that would count the elements in any array (not just the one given in the example above)

Explanation / Answer

Answer:

Assembly Language Code :

mov DWORD PTR [rbp-4], 28
mov eax, DWORD PTR [rbp-4]
cdqe
shr rax, 2
mov rsi, rax
mov edi, OFFSET FLAT:.LC0
mov eax, 0
  

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