Discussion in "8051 Discussion Forum" started by    sharath411    Jun 18, 2011.
Fri Jun 24 2011, 11:38 pm
#11
@Sharath, No - but you can use this C code to learn the method, and then convert it to assembly yourself. (note: This code will convert 8 digits, and does not contain any error checking - you should add that to your code to be sure )

I've separated out the individual steps into i1, i2, and i3 so you can see the values in your debugger...

void BCD32BIN32( uint32_t *in, uint32_t *out )
   {
   uint8_t i;
   uint32_t i1, i2, i3, mask = 0xF0000000;

   *out = 0x00000000;

   // 32 bits = 8 possible BCD values...
   for( i=0; i<8; i++ )
      {
      i1 = *in & mask;
      i2 = (7-i)*4;
      i3 = i1>
>
i2;
      *out += i3;
      // no need to multiply on units digit...
      if( i == 7 )
         break;
      *out *= 10;
      mask = mask >
>
 4;
      }
   }

void main( void )
   {
   uint32_t TestValue = 0x12345678;
   uint32_t ReturnValue;

   // TestValue has the BCD value in it...
   // Return Value is the binary equivalent...
   // -----------------------------------------
   BCD32BIN32( &TestValue, &ReturnValue );
   while(1);
   }


Hope this helps,


[ Edited Mon Jun 27 2011, 03:28 am ]

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am
utaletxcyw
Wed Apr 17 2024, 10:21 am
Anthonyvab
Wed Apr 17 2024, 08:48 am
RobertCix
Wed Apr 17 2024, 06:46 am