Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Binary to BCD with Assembly

Status
Not open for further replies.

mpch_elec

Member level 1
Joined
Jul 22, 2009
Messages
33
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Tehran,Iran
Activity points
1,505
hi friends,
I want to convert binary to BCD with assembly language.
my processor is AVR-Atmega 32.
Thanks.:???:
 

8 bit or 16 bit?

here is an 8 bit routine:
Code:
;*****************************************************
;* "bin2BCD8" - 8-bit Binary to BCD conversion
;* This subroutine converts an 8-bit number (temp) to a 2-digit 
;* i.e 0x15 becomes 0x21
;* result in temp
;**********************************************************
;.def	tBCD	= r21			;add this to main asm file
;
bin2bcd8:
	clr	tBCD			;clear temp reg
bBCD8_1:
	subi	Temp,10		;input = input - 10
	brcs	bBCD8_2		;abort if carry set
	subi	tBCD,-$10 		;tBCD = tBCD + 10
	rjmp	bBCD8_1		;loop again
bBCD8_2:
	subi	Temp,-10		;compensate extra subtraction
	add	Temp,tBCD	
	ret
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top