Saturday, April 30, 2016

8051 Program – addition multibyte

; addition multibyte numbers
; input: 4000H - 02H 4010H - 02H
; 4001H - 03H + 4011H - 03H
; 4002H - 04H 4012H - 04H
;output: 4020H - 04H
; 4021H - 06H
; 4022H - 08H
ORG 0H
NUM1_ADDR EQU 4000H
NUM2_ADDR EQU 4010H
RESULT_ADDR EQU 4020H
BYTE_COUNT EQU 3
MAIN:
MOV DPTR,#NUM1_ADDR ; fill memory
MOV A, #02H
MOVX @DPTR,A
INC DPTR
MOV A, #03H
MOVX @DPTR,A
INC DPTR
MOV A, #04H
MOVX @DPTR,A
MOV DPTR,#NUM2_ADDR
MOV A, #02H
MOVX @DPTR,A
INC DPTR
MOV A, #03H
MOVX @DPTR,A
INC DPTR
MOV A, #04H
MOVX @DPTR,A
LCALL MADD
SJMP MAIN
MADD:
CLR C
MOV R4,#BYTE_COUNT
MOV DPTR,#NUM1_ADDR
MOV R0,DPL
MOV R1,DPH
MOV DPTR,#NUM2_ADDR
MOV R2,DPL
MOV R3,DPH
MOV DPTR,#RESULT_ADDR
loop:
PUSH DPL
PUSH DPH
MOV DPL,R0
MOV DPH,R1
MOVX A,@DPTR
MOV B,A
INC DPTR
MOV R0,DPL
MOV R1,DPH
MOV DPL,R2
MOV DPH,R3
MOVX A,@DPTR
ADDC A,B
INC DPTR
MOV R2,DPL
MOV R3,DPH
POP DPH
POP DPL
MOVX @DPTR,A
INC DPTR
DJNZ R4,loop
RET
END



Related topics:
8051 Program - arithmetic operation 8bit   |   8051 Program - addition 8bit   |   8051 Program - subtraction 8bit   |   8051 Program - multiplication 8bit   |   8051 Program - division 8bit   |   8051 Program - addition 16bit   |   8051 Program - subtraction 16bit   |   8051 Program - multiplication 16bit   |   8051 Program - division 16bit   |   8051 Program - multiplication 16bit by 8bit   |   8051 Program - addition 8bit 2digit bcd   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment