Skip to content
Related Articles

Related Articles

8086 program to generate AP series of n numbers
  • Last Updated : 07 Jun, 2018

Problem – Write a program in 8086 microprocessor to generate arithmetic progression (AP) series of n eight bit numbers.

Assumptions –
Assume that size “n” is stored at offset 500 and the first number(a) is stored at offset 501 and the common difference is stored at offset 502. Store the series into memory address offset 600.

Example –

Algorithm –

  1. Store 500 to SI and 600 to DI Load data from offset 500 to register CL and set register CH to 00 (for count).
  2. Increase the value of SI by 1.
  3. Load first number(value) from next offset (i.e 501) to register AL.
  4. Store the value of register AL to memory offset DI.
  5. Increase DI by 1.
  6. Decrease the CL by 1.
  7. Load second number(common difference) from next offset (i.e 502) to register BL.
  8. Add register AL and BL.
  9. Store the result (value of register AL ) to memory offset DI.
  10. Increase the value of SI by 1.
  11. Loop above 3 till register CX gets 0.

Program –

MEMORY ADDRESSMNEMONICSCOMMENT
400MOV SI, 500SI<-500
403MOV CL, [SI]CL<-[SI]
405MOV CH, 00CH<-00
407INC SISI<-SI+1
408MOV AL, [SI]AL<-[SI]
40AINC SISI<-SI+1
40BMOV DI, 600DI<-600
40EMOV [DI], AL[DI]<-AL
410INC DIDI<-DI+1
411DEC CLCL<-CL-1
412MOV BL, [SI]BL<-[SI]
414ADD AL, BLAL<-AL+BL
416MOV [DI], AL[DI]<-AL
418INC DIDI<-DI+1
419LOOP 414JUMP TO 414 IF CX!=0 and CX=CX-1
41BHLTend

Explanation –

  1. MOV SI, 500: set the value of SI to 500.
  2. MOV CL, [SI]: load data from offset SI to register CL.
  3. MOV CH, 00: set value of register CH to 00.
  4. INC SI: increase value of SI by 1.
  5. MOV AL, [SI]: load value from offset SI to register AL
  6. INC SI: increase value of SI by 1.
  7. MOV DI, 500: set the value of DI to 600.
  8. MOV [DI], AL: store value of register AL at offset DI.
  9. INC DI: increase value of DI by 1.
  10. DEC CL: decrease value of register CL by 1.
  11. MOV BL, [SI]: load value from offset SI to register BL.
  12. MUL BL: add value of register AL by BL.
  13. MOV [DI], AL: store value of register AL at offset DI.
  14. INC DI: increase value of DI by 1.
  15. LOOP 414: jump to address 414 if CX not 0 and CX=CX-1.
  16. HLT: stop.
My Personal Notes arrow_drop_up
Recommended Articles
Page :