+ Post New Thread
Results 1 to 2 of 2
  1. #1
    Member level 1
    Points: 840, Level: 6
    mpch_elec's Avatar
    Join Date
    Jul 2009
    Location
    Tehran,Iran
    Posts
    33
    Helped
    3 / 3
    Points
    840
    Level
    6

    Binary to BCD with Assembly

    hi friends,
    I want to convert binary to BCD with assembly language.
    my processor is AVR-Atmega 32.
    Thanks.

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 2
    Points: 6,938, Level: 19
    ctownsend's Avatar
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    574
    Helped
    94 / 94
    Points
    6,938
    Level
    19

    Re: Binary to BCD with Assembly

    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



--[[ ]]--