I am trying out some C + ASM combi code using SDCC, using some code from:
used C VDP routines
The following two routines give odd results, I am wondering if this is a SDCC bug?
void puthex8(uint8 v) { puthex(2, (uint16) v); } //------------------------------------------------------------------------------ void puthex16(uint16 v) { puthex(4, v); }
when puthex8 is called with:
putdec8(flashid);
where flashid is of type unsigned char. With flashid = 19
It should print '13' but instead it prints:
1900000000000190000... repeated...
A quick gcc equivalent shows the code should work
#include #include #include void puthex(uint8_t nibbles, uint16_t v); void puthex8(uint8_t v); unsigned char hwid; void main() { hwid=19; puthex8(hwid); }; void puthex(uint8_t nibbles, uint16_t v) { int i = (int)nibbles - 1; while (i >= 0) { uint16_t aux = (v >> (i << 2)) & 0x000F; uint8_t n = aux & 0x000F; if (n > 9) printf("%c",('A' + (n - 10))); else printf("%c", ('0' + n)); i--; } } //------------------------------------------------------------------------------ void puthex8(uint8_t v) { puthex(2, (uint16_t) v); }
EDIT: the forum is ruining the code oO
Login or register to post comments