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.

what is the difference between an unsigned char and unsigned int in an 8051 kill compilers?

Status
Not open for further replies.

MRgenius

Junior Member level 3
Joined
May 14, 2015
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
174
what is the difference between unsigned char and unsigned int in 8051 kiel compiler

while i'm trying to debug the code i noticed something wired
when i define the variable as unsigned char i noticed there is no generated assembly cod in the dis-assembly window
when i convert it to unsigned int ,i get a generated assembly code for it
pic1.JPGpic2.JPG
here is the pictures for the two cases for simple example
 

Re: what is the difference between unsigned char and unsigned int in 8051 kiel compil

I already know that unsigned char is 8 bits
while unsigned int is 16 bit
my problem is that why i couldn't debug the unsigned char
 

Re: what is the difference between unsigned char and unsigned int in 8051 kiel compil

Can you tell me the errors that you are getting.

i couldn't debug the unsigned char variable as there is no generated assembly for it here is a simple program to test
Code:
void main()
{
	unsigned char count = 0 ;
	count++ ;
	count++ ;
	count++ ;
	count++ ;
	count++ ;
	count++ ;

while(1){}
}
 

Re: what is the difference between unsigned char and unsigned int in 8051 kiel compil

Looks like redundant code being removed in optimization. Declaring count as a global variable with volatile attribute should stop possible code optimization.

It's not clear at first sight why you get different results for char and int. Either there are other differences regarding variable declaration and usage, or it happens that optimization works different for both types.
 

Re: what is the difference between unsigned char and unsigned int in 8051 kiel compil

Can you please use this code and tell me the results.

Code:
unsigned char count;

void main()
{
	count++ ;
	count++ ;
	count++ ;
	count++ ;
	count++ ;
	count++ ;

while(1);
}

I tried this one before and it worked fine ...... i just want to figure out and learn why this happens when i declare it as a local variable

- - - Updated - - -

Looks like redundant code being removed in optimization. Declaring count as a global variable with volatile attribute should stop possible code optimization.

It's not clear at first sight why you get different results for char and int. Either there are other differences regarding variable declaration and usage, or it happens that optimization works different for both types.
i noticed that when i declare it as a global variable it works fine even without the Volatile attribute and it seems the optimization which do it ....is there any book to learn these tips?
 

Re: what is the difference between unsigned char and unsigned int in 8051 kiel compil

i noticed that when i declare it as a global variable it works fine even without the Volatile attribute and it seems the optimization which do it ....is there any book to learn these tips?
The behavior is generally compiler dependent, a detailed specification can be probably found in the Keil documentation.

It looks like Keil is not aggressively optimizing, I guess that it's implementing local 8-bit variables by default as register. Register variables may be dynamically reused during function lifetime, so the compiler is specifically checking their actual usage and in this case determining that it's not used at all.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top