; GCFof two numbers
; input: 4000H
; output: 4010H
ORG 0H
DATA_ADDR EQU 4000H
GCF_ADDR EQU 4010H
MAIN:
MOV DPTR,#DATA_ADDR
MOV A,#05
MOVX @DPTR,A
INC DPTR
MOV A,#02
MOVX @DPTR,A
LCALL GCF
SJMP MAIN
GCF:
MOV DPTR,#DATA_ADDR ;Load DATA_ADDR into dptr register
MOVX A,@DPTR ; move data from external memory location to a
MOV B,A ; move data from a to b
INC DPTR ;increment dptr
MOVX A,@DPTR ; move data from external memory location to a
back: MOV R1,B ;move data from b to r1
DIV AB ;divide a by b
MOV A,B ;move data from b to a
JZ store ;if a=0, jump to label store
MOV A,R1 ;move data from r1 to a
JMP back ;jump to label back
store: MOV DPTR,#GCF_ADDR ;Load dptr with GCF_ADDR
MOV A,R1 ;move data from r1 to a
MOVX @DPTR,A ;move data from a to external memory location
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 - fibonacci series | 8051 Program - lcm of two numbers | 8051 Program - memory subroutines | 8051 Program - math subroutines | 8051 Program - conversion subroutines
List of topics: 8051
No comments:
Post a Comment