Overview
I am trying to program a frequency divider using the MC9S08QD4 microcontroller. It uses an 8-bit architecture after the HCS08 instruction set ( documentation available here ).
However, in order to maximize the input frequency in a wide range, I have tried to use variables doubleand unsigned longstorage properties such as a period of the input signal.
I have a problem: whenever I assign values to variables doubleor long, it correctly assigns a value to this variable, but also overwrites completely unrelated parts of the memory, corrupting other variables that can be stored there. A colleague suggested that this may be due to the fact that he uses these places to store intermediate values during the calculation, which would be very strange if this happened.
Environment
These are the tools I'm working with as a link for the rest of this post:
- 64-bit machine for Windows 7.
- CodeWarrior Development Studio 10.7
More details
long double. "" , 16- , , , 32- .
/ , , , , , . , , , , .
, , , / :
S08 ansis.lib, small HCS08 32- 64- .
__NO_FLOAT__ , .
Use IEEE32 for double (default is IEEE64) HCS08 ( 32- ).
, HCS08 Compiler -> Type Sizes.
, .
SSCCE
:
static double temp = 0;
static double temp2 = 0;
static double temp3 = 0;
void main(void)
{
double a = 1000;
double b = a + 2;
temp = 1;
temp2 = temp + 2;
temp3 = temp2 + 3;
}
IDE :

. 0, , , . , , a :

, , b , :


main. HCS08 .
5 void main(void)
f092: A7F0 AIS #-16
7 double a = 1000;
f094: 5F CLRX
f095: 8C CLRH
f096: 9EFF07 STHX 7,SP
f099: 9EFF05 STHX 5,SP
f09c: 454000 LDHX #0x4000
f09f: 9EFF03 STHX 3,SP
f0a2: AE8F LDX #0x8F
f0a4: 9EFF01 STHX 1,SP
8 double b = a + 2;
f0a7: 95 TSX
f0a8: CDF4F1 JSR 0xF4F1 _DADD_RC (0xf4f1)
f0ab: 40 NEGA
f0ac: 000000 BRSET 0,0x00,*+3 main+0x15 (0xf0af)
f0af: 000000 BRSET 0,0x00,*+3 main+0x15 (0xf0b2)
f0b2: 00AF08 BRSET 0,0xAF,*+11 main+0x26 (0xf0bd)
f0b5: CDF13A JSR 0xF13A _POP64 (0xf13a)
double a = 1000; , , double b = a + 2;, , , .
, , .
Edit
( , ). , , , , , .