8086 program to find average of n numbers
Problem – Write an assembly language program in 8086 microprocessor to find average of n eight bit numbers.
Example –

Algorithm –
- Assign value 500 in SI and 600 in DI
- Move the contents of [SI] in CL
- Move 0000 in AX
- Move the contents of CL to BL
- Increment the value of SI by 1
- Add the contents of AL and [SI]
- Add 00 to AH with previous carry
- Increment the value of SI by 1
- Decrements the value of CL by 1
- If Zero Flag (ZF) is not set go to step 6 else go to step 11
- Divide the contents of AX by BL
- Move the contents of AX in [DI]
- Halt the program
Program –
| OFFSET | MNEMONICS | COMMENT |
|---|---|---|
| 400 | MOV SI, 500 | SI <- 500 |
| 403 | MOV DI, 600 | DI <- 600 |
| 406 | MOV AX, 0000 | AX = 0000 | 409 | MOV CL, [SI] | CL <- [SI] | 40B | MOV BL, CL | BL <- CL | 40D | INC SI | SI = SI + 1 | 40E | ADD AL, [SI] | AL = AL + [SI] | 410 | ADC AH, 00 | AH = AH + 00 + cy | 412 | INC SI | SI = SI + 1 | 413 | DEC CL | CL = CL – 1 | 415 | JNZ 40E | JUMP if ZF = 0 | 417 | DIV BL | AX = AX / BL | 419 | MOV [DI], AX | [DI] <- AX | 41B | HLT | Stop |
Explanation –
- MOV SI, 500 is used to move offset 500 to Starting Index(SI).
- MOV DI, 600 is used to move offset 600 to Destination Index(DI).
- MOV AX, 0000 is used to move data 0000 to AX.
- MOV CL, [SI] is used to move the contents of [SI] to BL.
- MOV BL, CL is used to copy contents of CL to BL.
- INC SI is used to increment contents of SI by 1.
- ADD AL, [SI] is used to add contents of [SI] to AL.
- ADC AH, 00 is used to 00 along with previous cy to AH.
- INC SI is used to increment contents of SI by 1.
- DEC CL is used to decrement contents of CL by 1.
- JNZ 40E is used to jump to offset 40E if value of ZF = 0.
- DIV BL is used to multiply contents of AX by BL.
- MOV [DI], AX is used to move the contents of AX to [DI].
- HLT stops executing the program and halts any further execution.
Recommended Posts:
- 8086 program to find sum of Even numbers in a given series
- 8086 program to find GCD of two numbers and print the GCD
- 8086 program to find sum of odd numbers in a given series
- 8086 program to determine squares of numbers in an array of n numbers
- 8086 program to determine cubes of numbers in an array of n numbers
- 8086 program to add two 8 bit BCD numbers
- 8086 program to multiply two 8 bit numbers
- 8086 program to add two 16 bit BCD numbers with carry
- 8086 program to subtract two 16 bit BCD numbers
- 8086 program to subtract two 8 bit BCD numbers
- 8086 program to add two 16-bit numbers with or without carry
- 8086 program to multiply two 16-bit numbers
- 8086 program to generate AP series of n numbers
- 8086 program to generate G.P. series of n numbers
- 8086 program to subtract two 16-bit numbers with or without borrow
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



