I saw your picture on your web page...
-Mark
Here's my Bin2Bcd4 routine. Compiles to 370 bytes (dec)
I like yours better.
/*******************************************************************
Convert from Binary to BCD
*******************************************************************/
unsigned long int Bin2Bcd4( unsigned long int val )
{
unsigned long int temp = 0;
temp = ( ( val ) % 10 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 4 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 8 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 12 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 16 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 20 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 24 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 28 );
return( temp );
}
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Steve
Underwood
Sent: Tuesday, June 10, 2003 9:50 AM
To: [email protected]
Subject: Re: [Mspgcc-users] FAQ
Mark Stokes wrote:
>Ya, the example looks good to me. In fact, I didn't know you could use
>useful labels for the asm vars, I have a few that all use A1 B2, etc.
>
This was introduced in GCC 3.1 or 3.2 (I forget which). It should have
happened years ago. Most of the errors in my embedded assembly language
seem to come from mixing up the numbered arguments. For larger variables
%A[name], %B[name], etc. work too.
>In my code, I just used straight C to convert from BCD to Bin (and vice
>versa), although, you're looks to be far more efficient.
>
I wouldn't normally use BCD on a modern 16-bit processor, but I use this
routine to get things in a form for easy output to an LCD display. If
you find that useful, you might also the 32 bit version below useful.
>On the assembly for the dadd, seems like you are going to a bit of
extra
>work, this too would work:
> __asm__( "DADD.W %A1, %A0 \n\t" : "=r" (bcd_a) : "r" (bcd_b) );
>
Err, yeah. I was treating DADD like the decimal adjust on some CPUs,
instead of a real BCD add function. Fixed.
>Found one pet peve:
>In file: x33.html, the word "its" is missing an apostrophe. The word
is
>
Fixed.
>short for "It is", I know you know this (being British), but some
others
>here might not :)
>
Whatever makes you think I am British? Haven't you noticed from the
timezone of my message that I am Asian? :-)
Regards,
Steve
void bin2bcd32(register uint8_t bcd[5], register uint32_t bin)
{
register int i;
register uint16_t decimal_0;
register uint16_t decimal_1;
register uint16_t decimal_2;
i = 16;
decimal_0 =
decimal_1 =
decimal_2 = 0;
__asm__ __volatile__(
"1: \n"
" rla %B4 \n"
" dadd %[decimal_0],%[decimal_0] \n"
" dadd %[decimal_1],%[decimal_1] \n"
" dadd %[decimal_2],%[decimal_2] \n"
" dec %[i] \n"
" jnz 1b \n"
" mov #16,%[i] \n"
"2: \n"
" rla %A[bin] \n"
" dadd %[decimal_0],%[decimal_0] \n"
" dadd %[decimal_1],%[decimal_1] \n"
" dadd %[decimal_2],%[decimal_2] \n"
" dec %[i] \n"
" jnz 2b \n"
" mov.b %[decimal_2],0(%[bcd]) \n"
" mov.b %[decimal_1],2(%[bcd]) \n"
" swpb %[decimal_1] \n"
" mov.b %[decimal_1],1(%[bcd]) \n"
" mov.b %[decimal_0],4(%[bcd]) \n"
" swpb %[decimal_0] \n"
" mov.b %[decimal_0],3(%[bcd]) \n"
: [bcd] "+r"(bcd), [decimal_0] "+r"(decimal_0), [decimal_1]
"+r"(decimal_1), [decimal_2] "+r"(decimal_2)
: [bin] "r"(bin), [i] "r"(i));
}
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users