problem with 8052 addtion

Hi,
please look into this code
Code:
#include "REG52.h"
#include "intrins.h"

void main()
{ long int data1 = 0xFF000000;
char shift = 0xA0; data1 = _lrol_(data1,8); data1 = data1 & 0xFFFFFF00; data1 = data1 + shift;
}

the value of data1 i expect is 0x000000A0, but when i execute the above code, it shows a value of data1 = 0xFFFFFFA0. I am not understanding why it should add 0xFFFFFF in its previous byte.

I am using Keil IDE-Version: µVision3 V3.60 and C Compiler: C51.Exe V8.12

Can anyone tell me, if something is wrong ?

regards,
Kume

Parents
  • void main()
    {
      long int data1 = 0xFF000000;
      char shift = 0xA0;
    
      data1 = _lrol_(data1,8);
      data1 = data1 & 0xFFFFFF00;
      data1 = data1 + shift;
    }
    

    That code has a good deal more problems than the one you saw with "addtion"(sic).

    * 0xFF000000 doesn't fit into a long int
    * 0xA0 may not fit into a char (depending on compiler settings)
    * _lrol_() is supposed to used with unsignedlong int
    * _lrol_() returns a value of a type different from that of data1
    * 0xFFFFFF00 doesn't fit into a long int

    Given all thos einfractions, any expectation formed about the result of that program is bound to be wrong.

Reply
  • void main()
    {
      long int data1 = 0xFF000000;
      char shift = 0xA0;
    
      data1 = _lrol_(data1,8);
      data1 = data1 & 0xFFFFFF00;
      data1 = data1 + shift;
    }
    

    That code has a good deal more problems than the one you saw with "addtion"(sic).

    * 0xFF000000 doesn't fit into a long int
    * 0xA0 may not fit into a char (depending on compiler settings)
    * _lrol_() is supposed to used with unsignedlong int
    * _lrol_() returns a value of a type different from that of data1
    * 0xFFFFFF00 doesn't fit into a long int

    Given all thos einfractions, any expectation formed about the result of that program is bound to be wrong.

Children
More questions in this forum