Saturday, April 30, 2016

8051 Program – fibonacci series

; generate Fibonacci series
; output: 4000H
ORG 0H
DATA_ADDR EQU 4000H
NO_OF_TERMS EQU 0AH
MAIN:
LCALL CONV
SJMP MAIN
CONV:
MOV R1,#NO_OF_TERMS ;load r1 with immediate data: NO_OF_TERMS
MOV DPTR,#DATA_ADDR ;load DATA_ADDR into dptr register
MOV A, #0 ; first term is 0
MOVX @DPTR,A
INC DPTR
MOV A, #1 ; second term is 1
MOVX @DPTR,A
MOV A,R1
SUBB A,#2 ;since we filled two terms
MOV R1,A
MOV DPTR,#DATA_ADDR ;load DATA_ADDR into dptr register
MOVX A,@DPTR ;move data from external memory location to a
INC DPTR ;increment dptr
MOV R0,A ;move data from a to r0
MOVX A,@DPTR ;move data from external memory location to a
back: MOV R2,A ;move data from a to r2
ADD A,R0 ;add a and r0
INC DPTR ;increment dptr
MOVX @DPTR,A ;move data from a to external memory location
MOV R3,A ;move data from a to r3
MOV A,R2 ;move data from r2 to a
MOV R0,A ;move data from a to r0
MOV A,R3 ;move data from r3 to a
DJNZ R1,back ;decrement r1, if not 0, jump to label back
RET
END



Related topics:
8051 Program - smallest element in an array   |   8051 Program - largest element in an array   |   8051 Program - factorial of a given number   |   8051 Program - lcm of two numbers   |   8051 Program - gcf of two numbers   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment