Assembly language program for Fibonacci Series


Program:

LXI H,3050 
MVI D,10    ; D is counter (D=10)
MVI B,00    ; B=00
MVI C,01    ; C=01
MOV M,B   ; Copy the content of B at memory location 3050 that is 00
INX H          ; increment the HL pair that is 3051 
MOV M,C   ; Copy the content of C at memory location 3051 that is 01
LOOP: MOV A,B  ; now A=B =00
ADD C          ;  A=A+C  => A=0+1=1 
MOV B,C     ; B=C=> 1
MOV C,A    ;  C=A=>1
INX H          ; increment the HL pair that is 3052
MOV M,A  ;  Copy the content of A at memory location 3052 that is 01
DCR D         ; Decrement counter that become 9
JNZ LOOP   ; go to the LOOP  if value of counter is not zero
HLT             ; terminate the program execution if counter become  0

Result:


Memory Location
Data value
3050
0
3051
1
3052
1
3053
2
3054
3
3055
5
3056
8
3057
13
3058
21
3059
34









Comments

Popular posts from this blog

Preamble to the Constitution of India:

Designing a calculator using HTML and JavaScript