Dear sdcc community,
I am encountering a problem that is somehow connected to the cast
between float and int, and it is unclear to me whether I am using sdcc wrong or
whether there might be a bug somewhere. Please find below two pieces of code,
the first one works as expected, the value of debug is 6116. The second does
not work, I expect the value to be 6116, but I see a different number. It is
not clear to me whether this is always the same number and what influences its
value.
I compile for a PIC16F1938, using sdcc from svn (rev8435), configured with
--enable-new-pics (since pic16f1938 uses the "enhanced core") against gputils
r932.
$ sdcc -v
SDCC :
mcs51/gbz80/z80/z180/r2k/r3ka/ds390/pic16/pic14/TININative/ds400/hc08/s08 3.2.1
#8435 (Feb 17 2013) (Linux)
I compile using
$ sdcc -I/usr/local/share/sdcc/non-free/include/
-L/usr/local/share/^Ccc/non-free/lib/pic14/ -L/usr/local/share/^Ccc/lib/pic14
-mpic14 -p16f1938 problem.c
When comparing the asm outputs I see that the first example does not call
___fs2uint, why does it not need to do this to cast the value of x? What else
can I
do to narrow the problem down? Is there a debugger in which I can run these
programs on my computer and inspect the values after each step? Currently I use
a board with connected LED displays to inspect the value of debug (program
attached).
Thank you for any help.
//Daniel
$ cat problem_works.c
#define __16f1938
#include <float.h>
#include "pic14/pic16f1938.h"
static __code int __at(_CONFIG1) __CONFIG1 = _WDTE_OFF;
unsigned int debug = 1234;
void main(void) {
float x = 6116.0;
debug = x;
//debug is 6116.
}
$ cat problem.c
#define __16f1938
#include <float.h>
#include "pic14/pic16f1938.h"
/* Setup chip configuration */
static __code int __at(_CONFIG1) __CONFIG1 = _WDTE_OFF;
unsigned int debug = 1234;
float julianday = 6116.0;
void main(void) {
float x = 6116.0;
debug = julianday;
// expect 6116, obtain a vastly different (arbitrary?) number
}
#define __16f1938
#include <float.h>
#include "pic14/pic16f1938.h"
#include "ledd.h"
#define FOSC 8000000L
#define delayus(x) { unsigned char us; us = (x)/(12000000/FOSC)|1; while(--us != 0)continue; }
void delayms(unsigned int ms) { unsigned char i;
do { i = 4;
do {
delayus(164);
} while(--i);
} while(--ms);
}
/* Setup chip configuration */
static __code int __at(_CONFIG1) __CONFIG1 = _WDTE_OFF;
//_CLKOUTEN_ON & _BOREN_OFF & _PWRTE_OFF & _MCLRE_OFF & _WDTE_OFF & _FOSC_INTOSC;//_HS_OSC;// & _INTRC_OSC_NOCLKOUT;
//_INTRC_OSC_NOCLKOUT & _PWRTE_OFF; // &_BOR_OFF & _IESO_OFF & _FCMEN_OFF; // _CP_OFF
int debug = 1234;
float julianday = 6116.0f;
void transmit (int n, char dot) {
char databyte;
n %= 10;
n += '0';
switch(n){
case '0': databyte = ZERO; break;
case '1': databyte = ONE; break;
case '2': databyte = TWO; break;
case '3': databyte = THREE; break;
case '4': databyte = FOUR; break;
case '5': databyte = FIVE; break;
case '6': databyte = SIX; break;
case '7': databyte = SEVEN; break;
case '8': databyte = EIGHT; break;
case '9': databyte = NINE; break;
case ' ': databyte = SPACE;break;
default: databyte = DASH; break;
}
if(dot) {
databyte |= 0b00001000;
}
SSPBUF = databyte;
}
void main(void) {
float x = 6116;
ANSELA=0x00;
ANSELB=0x00;
PORTA = 0x00;
PORTB = 0x00;
LATA = 0x00;
LATB = 0x00;
// SSP communication to the LED displays
BOEN = 1;
SSPCON1 = 0b00110000; //Configures SSP for serial communication (SPI master mode, clock = FOSC/4)
TRISA = 0x00;
TRISB = 0b11011000; //RB4 & RB5 are digital inputs
WPUB = 0b11011000;
TRISC = 0x00;
debug = julianday; // some large number, unexpected
//debug = x; // 6116 as expected
while(1) {
LATC2 = 0;
transmit(debug, 1);
transmit(debug / 10, 1);
transmit(debug /100, 1);
transmit(debug /1000, 1);
LATC2 = 1;
delayms(10);
}
}
------------------------------------------------------------------------------
The Go Parallel Website, sponsored by Intel - in partnership with Geeknet,
is your hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials, tech docs,
whitepapers, evaluation guides, and opinion stories. Check out the most
recent posts - join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user