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

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
  • hi,
    why do you try to play with ASM for such purposes? Next C lines produce the same result:

    unsigned char div(unsigned char x, unsigned char y)
    {
    	return (x/y);
    }
    
    unsigned char rem(unsigned char x, unsigned char y)
    {
    	return  (x%y);
    }
    

    Output file produced with compiler is:
    unsigned char div(unsigned char x, unsigned char y)
    MOV      A,R7
    MOV      B(0xF0),R5
    DIV      AB
    MOV      R7,A
    RET
    
    unsigned char rem(unsigned char x, unsigned char y)
    MOV      A,R7
    MOV      B(0xF0),R5
    DIV      AB
    MOV      R7,B(0xF0)
    RET
    

    So what is the reason to do same things which compiler may do itself?

    Regards,
    Oleg

Reply
  • hi,
    why do you try to play with ASM for such purposes? Next C lines produce the same result:

    unsigned char div(unsigned char x, unsigned char y)
    {
    	return (x/y);
    }
    
    unsigned char rem(unsigned char x, unsigned char y)
    {
    	return  (x%y);
    }
    

    Output file produced with compiler is:
    unsigned char div(unsigned char x, unsigned char y)
    MOV      A,R7
    MOV      B(0xF0),R5
    DIV      AB
    MOV      R7,A
    RET
    
    unsigned char rem(unsigned char x, unsigned char y)
    MOV      A,R7
    MOV      B(0xF0),R5
    DIV      AB
    MOV      R7,B(0xF0)
    RET
    

    So what is the reason to do same things which compiler may do itself?

    Regards,
    Oleg

Children