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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.