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
  • I noticed that the instruction d1=ACC is not converted into assembly (Keil ignores this line).

    What version of the tools do you use?

    I'm using V7.10 and it generates the following SRC file.

    ; unsigned char rem(unsigned char d1,unsigned char d2)
    
    	RSEG  ?PR?_rem?MAIN
    _rem:
    	USING	0
    			; SOURCE LINE # 3
    ;---- Variable 'd2?041' assigned to Register 'R5' ----
    ;---- Variable 'd1?040' assigned to Register 'R7' ----
    ; {
    			; SOURCE LINE # 4
    ; B=d2;
    			; SOURCE LINE # 5
    	MOV  	B,R5
    ; ACC=d1;
    			; SOURCE LINE # 6
    	MOV  	A,R7
    ;
    ; #pragma asm
    ; DIV AB;
    	  DIV AB;
    ; #pragma endasm
    ;
    ; return B;
    			; SOURCE LINE # 12
    	MOV  	R7,B
    ; }
    			; SOURCE LINE # 13
    ?C0001:
    	RET
    ; END OF _rem
    

    Note that d1 and d2 are stored in R5 and R7 and these are loaded into A and B registers.

    Jon

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

    What version of the tools do you use?

    I'm using V7.10 and it generates the following SRC file.

    ; unsigned char rem(unsigned char d1,unsigned char d2)
    
    	RSEG  ?PR?_rem?MAIN
    _rem:
    	USING	0
    			; SOURCE LINE # 3
    ;---- Variable 'd2?041' assigned to Register 'R5' ----
    ;---- Variable 'd1?040' assigned to Register 'R7' ----
    ; {
    			; SOURCE LINE # 4
    ; B=d2;
    			; SOURCE LINE # 5
    	MOV  	B,R5
    ; ACC=d1;
    			; SOURCE LINE # 6
    	MOV  	A,R7
    ;
    ; #pragma asm
    ; DIV AB;
    	  DIV AB;
    ; #pragma endasm
    ;
    ; return B;
    			; SOURCE LINE # 12
    	MOV  	R7,B
    ; }
    			; SOURCE LINE # 13
    ?C0001:
    	RET
    ; END OF _rem
    

    Note that d1 and d2 are stored in R5 and R7 and these are loaded into A and B registers.

    Jon

Children