adding all digits of a number, MCU 8051

Status
Not open for further replies.

PG1995

Full Member level 5
Joined
Apr 18, 2011
Messages
248
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
3,758
Hi

I want to add every digit in this number 457-85-9999-1, i.e. 4+5+7+8+.... I'm new to assembly language and using MCU 8051.

One way to do it is given below. How else can I do it efficiently and using few lines without making it complex for myself? Please help me with it. Thank you.

Code:
;add all digits of the number 457-85-9999-1

ORG 0H

	Repeat:
	CLR A
	ADD A, #4
	ADD A, #5
	ADD A, #7
	ADD A, #8
	ADD A, #5
	ADD A, #9
	ADD A, #9
	ADD A, #9
	ADD A, #9
	ADD A, #1
	SJMP Repeat

END

Regards
PG
 

if you want to add fix digits then you are right, but if digits are not fixed then you have to read & accumulative add them one by one from stack/array.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…