This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

compiler bug when using B and ACC

Anyone here with the same Problem?

I think that C51 V6.14 generates wrong code.

Chris


the following code

#pragma src
#include "80CL580.H"

extern handleLayer2Event( unsigned int );
//extern HandleLayer2Event( unsigned char, unsigned char );

#define EV_CHAR 0
#define EV_BADC 1

#pragma SAVE
#pragma AREGS
#pragma RB(1)

void isrHost() small
{
        CY = RB8;
        ACC = S0BUF;
        if( CY != P )
        {
            B = EV_BADC;
        }
        else
        {
            B = EV_CHAR;
        }

        handleLayer2Event( (unsigned int)B << 8 | ACC );
//        HandleLayer2Event( B, ACC );
}

#pragma RESTORE

results in

$NOMOD51

?PR?isrHost?M        SEGMENT CODE 
	EXTRN	CODE (_handleLayer2Event)
	PUBLIC	isrHost

	RSEG  ?PR?isrHost?M
isrHost:
	USING	1
	MOV  	C,RB8
	MOV  	A,S0BUF
	JNB  	P,?C0004
	CPL  	C
?C0004:
	JNC  	?C0001
	MOV  	B,#01H
	SJMP 	?C0002
?C0001:
	CLR  	A
	MOV  	B,A
?C0002:
	MOV  	R7,B
	MOV  	A,R7
	MOV  	R6,A
	MOV  	R7,A
	LJMP 	_handleLayer2Event

	END

with error in generating the unsigned int for handleLayer2Event().

Why it not generates the following.

?C0002:
	MOV  	R7,B
	MOV  	R6,A
	LJMP 	_handleLayer2Event

  • The root of the problem is that you are using 80C51 registers as variables - you cannot do this in C51 compiled code.

    C51 does allow access to registers, but this has to be done with great care. You cannot reasonably expect to be able to use the registers in the way that you have in your code.

    You should write your code using conventional 'C' variables or, if speed is your goal, code the function in assembly language.

    You cannot have your cake and eat it!