maarten wrote:
 > Hello Peter,
 > 
 > > In the main routine a printf gets the wrong value:
 > >
 > > extern __data uint8 * __data sys_rstack;
 > >
 > > // string for LCD output
 > > #define STR_LEN 80
 > > __xdata uint8 str[STR_LEN];
 > >
 > > main()
 > > {
 > >         sprintf (str,"%x", (uint8) *sys_rstack);
 > >         lcd_print(2, str);
 > >
 > >    generates:
 > >                             707 ;       main.c:107: sprintf (str,"%x",
 > > (uint8) *
 > > sys_rstack);
 > >    01B4 A9 10               708         mov     r1,_sys_rstack
 > >    01B6 87 07               709         mov     ar7,@r1
 > >    01B8 C0 07               710         push    ar7
 > >    01BA 74 53               711         mov     a,#__str_3
 > >    01BC C0 E0               712         push    acc
 > >    01BE 74 7E               713         mov     a,#(__str_3 >> 8)
 > >    01C0 C0 E0               714         push    acc
 > >    01C2 74 80               715         mov     a,#0x80
 > >    01C4 C0 E0               716         push    acc
 > >    01C6 74 DC               717         mov     a,#_str
 > >    01C8 C0 E0               718         push    acc
 > >    01CA 74 01               719         mov     a,#(_str >> 8)
 > >    01CC C0 E0               720         push    acc
 > >    01CE E4                  721         clr     a
 > >    01CF C0 E0               722         push    acc
 > >    01D1 12 7D 15            723         lcall   _sprintf
 > >    01D4 E5 81               724         mov     a,sp
 > >    01D6 24 F9               725         add     a,#0xf9
 > >    01D8 F5 81               726         mov     sp,a
 > >                             727 ;       main.c:108: lcd_print(2, str);
 > >
 > > The code above appears to be loading the contents of
 > > sys_rstack (at 0x10 in data) in to r7 but something undesirable happens
 > > after that (which may well be operator error on my part).
 > 
 > Since you use an explicit cast to char on the parameter passed to a
 > varargs function (sprintf) the value is not passed as an int as normal.
 > This is an extension to save memory. But then your formatter must also
 > tell it to expect a char instead of an int as %x does. Maybe it's better
 > to just remove the inline cast.

what difference does the cast make?  the declaration is already
uint8, so isn't the cast a no-op?  what am i missing?

this sdcc behavior bites us (bytes us?  :-) all the time -- i'm always
having to go back to add "(uint)foo" casts when printing byte-wide
values as %x or %d, to make the values show correctly.  unless there
are new format chars for byte-wide parameters, how does this save
memory?

what am i missing?

paul

 > 
 > HTH,
 > Maarten
 > 

=---------------------
 paul fox, p...@laptop.org

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to