[A89] Re: BCD in sprintf


[Prev][Next][Index][Thread]

[A89] Re: BCD in sprintf




First, if you could give the C-sytle prototype so we
know what order the parameters are in, that would
help.
Next:
>>lea     -30(sp),sp
>>DispString:
>>      .string "r=%f"

>>>This looks correct to me, except that I don't know
>>>about ".string"; 
>>>whether
>>>it even exists in A68k.  Could you try removing
>>>the "%f" in the 
>>>string,
>>>just to test the call to sprintf?

it's GNU as syntax. The sprintf works ok.
Really. Then, do you have --register-prefix-optional
switch passed, otherwise you should have %'s before
your registers.

>>in returns "r=0", I tried with the format string
"r=%
>>d,%d,%hi" and it 
>>returned "r=0,19456,3". I know that 19456 is for the

>>4C00 (the 
>>exponent of the BCD), but the "3"?...
Um, the BCD has the exponent first, so it should
probably be
"r=%hi,%li,%li". I'm not sure about int sizes with
TIOS, but they might only be 2 bytes, so you could
just be getting the first part of the mantissa.
Lastly, here's the C source code:
void _main(void)
{
	char buffer[20];
	sprintf (buffer, "r=%f", 1.2345);
	ST_helpMsg (buffer);
}
and the generated asm for that source, to demonstrate
how to use bcd in sprintf. It works fine for me:
	.data
.LC1:
	.ascii "r=%f\0"
	.even
.LC0:
	.word	16384
	.long	305418240
	.long	0
	.even
	.globl	_main
_main:
#APP
	/* Support for OPTIMIZE_ROM_CALLS */
	move.l 0xC8,%a5
#NO_APP
	link.w %a6,#-20
	move.l %a2,-(%sp)
	move.w .LC0+8,-(%sp)
	move.l .LC0+4,-(%sp)
	move.l .LC0,-(%sp)
	pea .LC1
	lea (-20,%a6),%a2
	move.l %a2,-(%sp)
	move.l 332(%a5),%a0
	jbsr (%a0)
	move.l %a2,-(%sp)
	move.l 920(%a5),%a0
	jbsr (%a0)
	move.l -24(%a6),%a2
	unlk %a6
	rts
Hope that helps.

__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com



Follow-Ups: References: