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

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am