Forth 10 times slower than C?



I've tried to use Forth on a LPC2148 microcontroller, with this nice board:
http://www.sparkfun.com/commerce/product_info.php?products_id=676

First I've tested it with an evaluation version of CrossStudio in C with
this program:

typedef unsigned char ui8;

#define FIO1DIR3 (*((volatile ui8 *) 0x3FFFC023))
#define FIO1MASK3 (*((volatile ui8 *) 0x3FFFC033))
#define FIO1SET3 (*((volatile ui8 *) 0x3FFFC03B))
#define FIO1CLR3 (*((volatile ui8 *) 0x3FFFC03F))
#define SCS (*((volatile ui8 *) 0xE01FC1A0))

void initPorts()
{
SCS = 3;
FIO1DIR3 = 1;
FIO1MASK3 = 0;
}

void ledOn()
{
FIO1SET3 = 1;
}

void ledOff()
{
FIO1CLR3 = 1;
}

void blink()
{
while (1) {
ledOn();
ledOff();
}
}

int main (void)
{
initPorts();
blink();

return 0;
}

The LED is blinking with about 2.4 MHz. Then I've downloaded and flashed
this Forth implementation:

http://www.mpeforth.com/arena.htm#lpcforth

and tested it with the same program in Forth:

\ Fast I/O setup
$3FFFC000 constant FIO_BASE_ADDR
FIO_BASE_ADDR $20 + constant FIO1DIR
FIO_BASE_ADDR $30 + constant FIO1MASK
FIO_BASE_ADDR $38 + constant FIO1SET
FIO_BASE_ADDR $3C + constant FIO1CLR

\ System Control Block(SCB)
$E01FC000 constant SCB_BASE_ADDR

\ System Controls and Status
SCB_BASE_ADDR $1A0 + constant SCS

: init-ports
3 SCS c! \ enable fast IO
1 FIO1DIR 3 + c! \ set LED pin output
0 FIO1MASK 3 + c! \ set mask
;

\ enable LED
: led-on 1 FIO1SET 3 + c! ;

\ disable LED
: led-off 1 FIO1CLR 3 + c! ;

\ very fast blink
: blink
begin
led-on
led-off
again ;

\ test
init-ports
blink

But the LED is blinking with about 275 kHz, only.

I know, it is a bit unfair, because the C compiler has the full power of a
PC for optimizing the code and the Forth system uses only less than 64 kB
for the whole system, including compiler on the target hardware, which is
really nice, but what can I expect from a Forth cross compiler? Are there
faster ANS Forth systems or cross compilers for the ARM7TDMI-S CPU
available, which are easy to use with the LPC2148 microcontroller?

--
Frank Buss, fb@xxxxxxxxxxxxx
http://www.frank-buss.de, http://www.it4-systems.de
.



Relevant Pages

  • Re: Blinking LED with C18
    ... It is the exact code that came from one of there ... I was able to make the 16F688 blink using assembly but I'm ... void delay (void) ... /* Make all bits on the Port B (LEDs) output bits. ...
    (sci.electronics.basics)
  • Re: Blinking LED with C18
    ... It is the exact code that came from one of there ... I was able to make the 16F688 blink using assembly but I'm ... void delay (void) ... /* Make all bits on the Port B (LEDs) output bits. ...
    (sci.electronics.basics)
  • Blinking LED with C18
    ... but the LED doesn't blink or even come on. ... void delay (void) ... /* Make all bits on the Port B (LEDs) output bits. ...
    (sci.electronics.basics)
  • Re: Blinking LED with C18
    ... I was able to make the 16F688 blink using assembly but I'm ... void delay (void) ... /* Make all bits on the Port B (LEDs) output bits. ...
    (sci.electronics.basics)
  • Global Variables Being Overwritten
    ... void LCDWrite(char *buffer) ... Freescale 68HC08 microcontroller. ...
    (comp.arch.embedded)

Loading