Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/08/11 06:50
Read: times


 
#181486 - bit type function parameter
Hi

We are using 8052 in our project. We are using Keil C51 cross-compiler.

There are some functions in the code, whose parameter passing value is either 1 or 0 always, and is as shown:
static void sendDataByte(const unsigned char i,const unsigned char y_n)
{
	if(y_n)
	{
		//related code execution
	}
	else
	{
		//related code execution
	}
}

void main(void)
{
	//code
	//code

	sendDataByte(0xFF,0);

	//code
	//code

	sendDataByte(0xAA,1);
}

 


As there are so many functions in the project code defined and called in this manner, we changed the definitions of those functions as:


static void sendDataByte(const unsigned char i,const bit y_n)
{
	if(y_n)
	{
		//related code execution
	}
	else
	{
		//related code execution
	}
}
 


The code is compiled without any error and the project hardware is working fine.
There is a new entry created in .m51 file of Keil as:
TYPE    BASE      LENGTH    RELOCATION   SEGMENT NAME
-----------------------------------------------------
BIT     002FH.5   0000H.1   UNIT         _BIT_GROUP_
-----------------------------------------------------

 

For this usage, PC-Lint generated the message:

Info 747: Significant prototype coercion (arg. no. 2) char to bool

So, we modified the function calling as shown, and the PC-Lint message cleared:

sendDataByte(0xFF,(bit)0);

Referring to Keil Cx51 User's Guide - Function Declarations - Parameters and Registers

-----------------------------------------------------------------------------

In the help file, the registers used for different argument positions and data types (char, int, long) were explained as:
-----------------------------------------------------------------------------
Argument	char		 int		long
Number	     1-byte ptr       2-byte ptr	float		 generic ptr 	--------------------------------------------------------------------------------------
   1		R7		R6 & R7		R4-R7		    R1-R3 
   2		R5		R4 & R5		R4-R7		    R1-R3 
   3		R3		R2 & R3			            R1-R3 
-----------------------------------------------------------------------------

 

Related to bit type:

If the first parameter of a function is a bit type, then other parameters are not passed in registers. This is because parameters that are passed in registers are out of sequence with the numbering scheme shown above. For this reason, bit parameters should be declared at the end of the argument list.

Q. What about the registers / flags used for bit type function parameter? For function return values of bit type, it is listed that the Carry Flag(CY) is used.

Q. What is the difference between unsigned char and bit types in function parameters?

Thanks in advance.


List of 17 messages in thread
TopicAuthorDate
bit type function parameter            01/01/70 00:00      
   Look at instruction set            01/01/70 00:00      
   What is your actual problem here?            01/01/70 00:00      
      main concern is code operation.            01/01/70 00:00      
         parameter converted to global variable            01/01/70 00:00      
            No reentrancy            01/01/70 00:00      
               Is it the 8051 instruction set?            01/01/70 00:00      
               Still looked at the bit capabilities of the processor?            01/01/70 00:00      
         You need to ask Keil            01/01/70 00:00      
         Use bool to simplify            01/01/70 00:00      
            BOOLEAN directive used            01/01/70 00:00      
               stdbool            01/01/70 00:00      
               Use stdbool            01/01/70 00:00      
                  Optimal implementation            01/01/70 00:00      
                     SDCC            01/01/70 00:00      
                        Optimal for what?            01/01/70 00:00      
                           both            01/01/70 00:00      

Back to Subject List