Write a 80 86 code fragment that accesses each element of an array (anArray) and
ID: 3624307 • Letter: W
Question
Write a 80 86 code fragment that accesses each element of an array (anArray) and stores the array elements which are below average in another array (bArray).1. Assume the following data section.
anArray DWORD 100 DUP(?) ; maximum size of a number array
count DWORD ? ; actual number of array elements
avg DWORD ? ; average of array elements
bArray DWORD 1000 DUP (?) ; maximum size of a number array
2. Assume that the actual number of array elements is stored in count.
3. You do not need to compute the average. Assume that the average of the array is stored in avg.
Explanation / Answer
Dear, .model small .stack 100h .data ; intialize data segment anArray DWORD 100 DUP(?) count DWORD ? avg DWORD ? bArray DWORD 1000 DUP(?) .code main proc mov ax, @anArray ; array initialization mov ds, ax mov bx, @bArray ; below array average initialization mov si, offset anArray mov di, offset bArray mov cx, count ; count the number of array l1: mov al,[si] inc cx inc si add dx, ax ; sum the array elements cmp cx, 0 ; check the count jae l1 mov cx, count ; initialize count div dx, cx ; calculate average mov al, [si] ; initialize array inc cx ; increment the count inc si ; increment source index to compare cmp dx, ax ; compare with average jb l2 ; if its less than average exit l2: mov [di], al ; store in another array inc di exitRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.