Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem with 8052 addtion

Status
Not open for further replies.

kumeemb

Junior Member level 3
Junior Member level 3
Joined
Nov 12, 2006
Messages
26
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,502
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 0xFFFFFFA0. I am not understanding why it should add 0xFFFFFF in 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
 

Hi jayanth,
I require a 32 bit data for data1, which i will be using it further. so i got to use Long int for data1.

regards,
Kume
 

Hi jayanth,

Based on your point, I think i got the solution to my problem
Code:
unsigned long data1 = 0xFF000000;
unsigned char shift = 0xA0;
				 data1 = _lrol_(data1,8);
				 data1 = data1 & 0xFFFFFF00;
				 data1 = data1 + shift;

Thank you for enlightening me about unsigned... i forgot about it though :)

But, if i go back and see the mistake i did..
without keyword 'unsigned' it was considering as signed long and singed char [if i am right], but is it natural for any complier to add FF when it is typecasting to long int ?? why should it do ?? can you please explain ?
 

I think the FFFFh your are getting is after rotating and shifting signed number. See about how ROL, ROR, SHL, SHR works for signed and unsigned numbers. If it doesn't append Fh or 0b1 to the sign bit then the sign changes while rotating or shifting.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top