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

maybe bug: far argument to printf fails

Hallo,

I may have hit a bug in CX51 Ver 7.06.
If a far variable is passed as an argument
to printf function; it fails. I wrote
this program:

#include <Philips\reg51m.h>
#include <stdio.h>

#pragma USERCLASS (HDATA=MYRAM)

far long int l ;

void main ()
{
	T2CON = 0x34 ;
	RCAP2H = 0xff ;
	RCAP2L = 0xdc ;
	SCON = 0x70 ;
	TI = 1 ;
	l = 100 ;
	printf("simple text message\n") ;
	printf("value = %ld\n",l) ;
	printf("value = %ld\n",12345678L) ;
}

The first printf works ok.
The second fails. It prints nothing.
The third again works ok.
I looked at the assembler code generated
by the compiler, and I think it is a bug:

; 	printf("simple text message\n") ;
			; SOURCE LINE # 16
	MOV  	R3,#BYTE2 (?SC_0)
	MOV  	R2,#HIGH (?SC_0)
	MOV  	R1,#LOW (?SC_0)
	LCALL	_printf
; 	printf("value = %ld\n",l) ;
			; SOURCE LINE # 17
	MOV  	R3,#BYTE2 (l)
	MOV  	R2,#HIGH (l)
	MOV  	R1,#LOW (l)
	LCALL	?C?LLDPTR
	MOV  	?_printf?BYTE+06H,R7
	MOV  	?_printf?BYTE+05H,R6
	MOV  	?_printf?BYTE+04H,R5
	MOV  	?_printf?BYTE+03H,R4
	LCALL	_printf
; 	printf("value = %ld\n",12345678L) ;
			; SOURCE LINE # 18
	MOV  	R3,#BYTE2 (?SC_21)
	MOV  	R2,#HIGH (?SC_21)
	MOV  	R1,#LOW (?SC_21)
	MOV  	?_printf?BYTE+06H,#04EH
	MOV  	?_printf?BYTE+05H,#061H
	MOV  	?_printf?BYTE+04H,#0BCH
	MOV  	?_printf?BYTE+03H,#00H
	LJMP 	_printf

Is this really a bug, or am I doing something
wrong?
If I am wrong, then what is right?
If this is a bug, then is there a workaround?

thanks to all readers!

mk

0