Forth is a great little language, and a perfect example of how to to do a surprising amount with very little. For more complicated embedded work, however, I've been deeply impressed with Philipp Oppermann's tutorial on writing a kernel in Rust: http://os.phil-opp.com/ You have to limit yourself to Rust's "core" library (instead of the usual "std"), and you won't have a heap until you write one, but it's surprisingly nice. Well, except for debugging double faults. That's never nice. :-/
Here's my toy PIC 8592 interface in pure Rust: https://github.com/emk/toyos-rs/tree/master/crates/pic8259_s... Be careful, it's a subtle chip and I only deal with the basics.
But if you're working in a raw microconroller, you're going to be touching metal constantly, and you won't want anything you don't use slowing you down.
In short, Rust is great, but it doesn't beat Forth in Forth's biggest problem space: programming embedded systems under exceptionally tight size/speed constraints.
Comparing it to Rust is missing this point entirely. Finally, let's not forget that Forth has been empirically validated multiple times in this domain (e.g. NASA has used Forth on board satellites and spacecraft).
Rust is entirely unproven in the hardware/microcontroller space (some would say in general), so I tend to view posts like ekidd's ("for more complicated embedded work") as projecting/wishful thinking.
But this is a huge draw for Forth, speaking as a Lisp user.
Not really.
https://www.mikroe.com/mikrobasic/
https://www.mikroe.com/mikropascal/
http://www.astrobe.com/default.htm
http://www.adacore.com/gnatpro/embedded
http://www.ptc.com/developer-tools/apexada
http://www.ghs.com/products/ada_optimizing_compilers.html
Zero lines of C.
Some of these do look neat: I've had an interest in both Ada and Oberon, although I haven't been able to get over the verbosity and unpleasant syntax of either (it's not COBOL, or anything, but it's not nice).
OTOH, I am immediately suspicious of any product that claims it's professional and also has BASIC in the name...
For many years the Elektor magazine and a few other competing ones, had the listings of electronic stuff done in Assembly, Basic and Turbo Pascal.
Before Raspberry PI was a thing, many developers were using Basic STAMP.
https://www.parallax.com/catalog/microcontrollers/basic-stam...
Although I suppose it does depend on the dialect, to an extent...
Of course there are other systems programming "monolithic executable" programming languages that allow straightforward access to memory mapped hardware registers.
www.esmertec.com
In what way does C understand interrupts?
And yeah, it's a given that it's going to be non-portable.
Given asm, implementing a Turbo C-style int86() function seems pretty trivial. It might even be doable as a macro.
asm {
mov ax, 0x0013
int 0x10
}
Can't really like the way clang and gcc asm work, even it it means giving more info to the optimizer. int foo(int c)
{
int r;
asm {
mov ax, 0x0b00
int 0x21 /* poll stdin for input */
mov ax, offset c /* get address of `c` */
call bar /* call other C function */
mov r, dx /* save the result in `r` */
}
return r;
}
Or something like that — it's been a while. Those were the days! GCC's (and I'm assuming clang's is much the same) inline assembly is a joke in comparison. I remember, when I first encountered it, flipping back-and-forth through the GCC docs looking for how people actually do inline asm with GCC...
Of all the alternatives to C, Forth is the only one which groks hardware. This is particularly important for embedded development. Any realistic alternative to C must understand interrupts, memory mapped registers etc.. Forth is the only one in which this is possible. Every other example I've seen always uses C for "low-level" access or a libraries. If you need to do that, then you won't win over embedded devs like me. It's much easier to write good embedded C code (no mallocs etc) than having to debug FFI.
Having said all that, my mind doesn't understand Forth. I'm too used to seeing code in C or even assembly to fully understand Forth. Nevertheless things like https://github.com/jeelabs/mecrisp-stellaris are really cool and are a realistic alternative to C.