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.
Please Login to comment...