Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to calculate the avg of "every" 3 elements in an array (the size of the array doesn't really matter right now) and set this avg value to these 3 elements using assembly language 8086

What I have tried:

i've tried to do it myself but i just couldn't..i assume we will use an array of whatever size then loop on that array byt counter (3) then calculate the avg and set the avg value to these 3 elements
Posted
Updated 12-Dec-17 21:46pm
Comments
Mehdi Gholam 13-Dec-17 0:45am    
What have you tried?

1 solution

That depends on the type of data (bit width with integers or single/double precision floating point values) and if overflow can occur and should be handled.

For 16-bit int with no overflow detection and array address in ds:si:
[EDIT: Fixed wrong offsets]
AvgLoop:
        ; Check for end of array here
        mov ax,[si]
        add ax,[si+2]
        add ax,[si+4]
        mov cx,3
        mov dx,0
        div cx
        mov [si],ax
        mov [si+2],ax
        mov [si+4],ax
        add si,6
        jmp AvgLoop
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900