Saturday, April 30, 2016

8051 Program – sum of a set of numbers

;sum of a set of numbers
;the sum is held by registers A and R7,
;where A has the low byte and R7 has the high byte.
ORG 0H
MEM EQU 40H
COUNT EQU 10
MAIN:
MOV R0,#MEM ; pointer to memory
MOV R2,#COUNT ; number of values
LCALL SUM
SJMP MAIN
SUM:
CLR A ; clear accumulator
MOV R7, A ; clear R7
again: ADD A, @R0 ; A= A+ value at R0
JNC next ; Jump if No carry
INC R7 ; accumulate carry, if set
next: INC R0 ; increment pointer
DJNZ R2, again ; repeat until R2 = 0
RET
END



Related topics:
8051 Program - sum of set of numbers in external ram   |   8051 Program - average of a set of numbers   |   8051 Program - arithmetic operation 8bit   |   8051 Program - addition 8bit   |   8051 Program - subtraction 8bit   |   8051 Program - move block of data external memory   |   8051 Program - ram to ram   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment