Problem with function call

In the following code:
********************************************
#include <REG51.H>

unsigned char rem(unsigned char d1,unsigned char d2)
{

B=d2;
ACC=d1;
#pragma asm
DIV AB;
#pragma endasm
return B;
}

void main(void)
{
while(1)
{
unsigned char x,y,z;
P0=255;
x=65;
y=10;

z=rem(x,y);
P0=z;
}
}

*****************************************
I noticed that the instruction d1=ACC is not converted into assembly (Keil ignores this line).

Is this any reason behind that?..How can I solve the problem?

Thanks

Parents
  • Trying to utilize commonly used registers like ACC, R0-R7, B, DPTR, SP, etc. directly from C is not a good idea. You should learn the compiler's calling conventions and register usage, then expand the scope of your 'asm' pragmas and code anything that deals with registers in assembly.

Reply
  • Trying to utilize commonly used registers like ACC, R0-R7, B, DPTR, SP, etc. directly from C is not a good idea. You should learn the compiler's calling conventions and register usage, then expand the scope of your 'asm' pragmas and code anything that deals with registers in assembly.

Children
More questions in this forum