C4SX: Why use C? Here is a sample C program that runs on both the SX48 and Win
Greetings. If you are interested in running C on the SX chips, the attached sample C program might be of interest to you.
Attached is a sample C program, called prime48.c, that counts the number of prime numbers between
2 and 100, and prints out the answer (which is 25).
What is interesting is that this exact same program, unmodified, also works under the Windows VC6 C compiler.· The Windows exe file is included in the attached zip.· Note that, with the SX48, ·th results are output with the I/O functions in the C4SX sxio.h library.· This SX prgm·can also be run on the· SX48 without serial support (let the debugger stop at the break point....).
This program is a bit of nonsense as who would want to·compute/find primes on a microcontroller??· But, it also makes a small point:· What other language can be used to write programs that can be tested under Windows and, unmodified, run on the SX?·· /* in other words, this is a very shameless plug for using C .... */··
On a serious note, this all works by using C #ifdef .... #endif sequences to keep the SX and Windows-specific code seperated.· In other words, the code is ported to both the SX and Windows platforms.
RW Senser
Attached is a sample C program, called prime48.c, that counts the number of prime numbers between
2 and 100, and prints out the answer (which is 25).
What is interesting is that this exact same program, unmodified, also works under the Windows VC6 C compiler.· The Windows exe file is included in the attached zip.· Note that, with the SX48, ·th results are output with the I/O functions in the C4SX sxio.h library.· This SX prgm·can also be run on the· SX48 without serial support (let the debugger stop at the break point....).
This program is a bit of nonsense as who would want to·compute/find primes on a microcontroller??· But, it also makes a small point:· What other language can be used to write programs that can be tested under Windows and, unmodified, run on the SX?·· /* in other words, this is a very shameless plug for using C .... */··
On a serious note, this all works by using C #ifdef .... #endif sequences to keep the SX and Windows-specific code seperated.· In other words, the code is ported to both the SX and Windows platforms.
RW Senser
ZIP
![](/plugins/FileUpload/images/file.png)
19K