If nothing else it inspired me to install FreeBASIC on my Pi 3B, which was an entirely painless venture thanks to scruss's instructions here -
LOL, I remember the days of the BASIC Wars, I also remember the System Wars (Amiga vs Atari ST vs Macintosh vs Archimedes), the fodder of Demo codinghippy wrote: ↑Wed Nov 21, 2018 2:29 pmIf nothing else it inspired me to install FreeBASIC on my Pi 3B, which was an entirely painless venture thanks to scruss's instructions here -
http://scruss.com/blog/2015/03/25/runni ... spberry-pi
The build took just over 4 minutes on a Pi 3B. Coming back to it after some time away means I can treat it as the language it is, and it seems pretty good with just a quick play. I guess we can start the Basic Wars now as to which is best and which everyone should be using![]()
Code: Select all
Assembler 0.3KB
C 5.3KB
BASIC 214KB
python2 3.1MB
python3 3.8MB
Javascript 15.0MB
BBC BASIC on RISC OS is even smaller, and in the ROM image so no added memory.jahboater wrote: ↑Wed Nov 21, 2018 2:54 pmTalking about memory usage, I see that BBC Basic V (brandy) is very small compared to the other interpreters.
214KB Got to be a good thing!
To run a simple hello world program you have to load the interpreter first:Code: Select all
Assembler 0.3KB C 5.3KB BASIC 214KB python2 3.1MB python3 3.8MB Javascript 15.0MB
Thank you. Though the 3B+ is notably faster than the 3B. It would be nice to see on a 3B what it is.
If its compiled there is no need to load an interpreter. Should be pretty small.
My asm program is just this - the executable is actually 352 bytes (probably just the ELF overhead)
Code: Select all
.global _start
_start:
mov r0,#1
ldr r1,=str
mov r2,#13
mov r7,#4
svc 0 // write
mov r0,#0
mov r7,#1
svc 0 // exit
str:
.ascii "Hello, world\n"
Yes the ELF overhead can be greater, if allowed to be. Though you will likely save a good bit just by using the older a.out format (not file name, actual file format), as it has less overhead, assuming that Linux still supports it (last I checked Linux still did).jahboater wrote: ↑Wed Nov 21, 2018 3:14 pmIf its compiled there is no need to load an interpreter. Should be pretty small.
My asm program is just this - the executable is actually 352 bytes (probably just the ELF overhead)Code: Select all
.global _start _start: mov r0,#1 ldr r1,=str mov r2,#13 mov r7,#4 svc 0 // write mov r0,#0 mov r7,#1 svc 0 // exit str: .ascii "Hello, world\n"
Graphics Library? BBC BASIC V does have builtin graphics commands, though they are built into the interpreter, no external library needed.I see what you mean about the small size on RISC OS because the interpreter is included in the OS kernel and doesn't have to be loaded first.
Same applies the graphics library I presume.
Not sure how you do that. "ld hello.o" creates an a.out file in ELF format! There used to be something called superstrip that could remove most of the ELF sections and still leave the program executable.DavidS wrote: ↑Wed Nov 21, 2018 3:30 pmYes the ELF overhead can be greater, if allowed to be. Though you will likely save a good bit just by using the older a.out format (not file name, actual file format), as it has less overhead, assuming that Linux still supports it (last I checked Linux still did).
I do not remember the ld command line well enough. Though there should be switch for the output format, that would be used to specify what format to put it into.jahboater wrote: ↑Wed Nov 21, 2018 3:44 pmNot sure how you do that. "ld hello.o" creates an a.out file in ELF format! There used to be something called superstrip that could remove most of the ELF sections and still leave the program executable.DavidS wrote: ↑Wed Nov 21, 2018 3:30 pmYes the ELF overhead can be greater, if allowed to be. Though you will likely save a good bit just by using the older a.out format (not file name, actual file format), as it has less overhead, assuming that Linux still supports it (last I checked Linux still did).
Superstrip "sstrip" gets the hello world program down to 135 bytes!
If you want to know if it is correct or not 3 ways:
Unfortunately that is one thing that is not quite as simple in BASIC (or C, or Pascal). Though to print it in hex would be easy enough.
Code: Select all
#include <stdio.h>
#include <gmp.h>
#include <time.h>
int main( void )
{
mpz_t res;
mpz_init( res );
double startTime = (float)clock()/CLOCKS_PER_SEC;
mpz_fib_ui( res, 4784969 );
double endTime = (float)clock()/CLOCKS_PER_SEC;
double timeElapsed = endTime - startTime;
gmp_printf( "%Zd\n", res );
printf("%f\n", timeElapsed);
}
For interest/amusement - printing seems to be more costly than executing it:-
Code: Select all
$ ./fibo >/dev/null
Exec time = 41 ms, Print time = 153 ms
$
No, I am not.Are you saying there is something wrong with my implementation of the algorithm?
Yep. All that binary to decimal conversion takes a long time:...printing seems to be more costly than executing it...
Code: Select all
$ time ./fibo
...
6330930391815964864885353407167474856539211500699706378405156269
0.031250
real 0m0.283s
user 0m0.141s
sys 0m0.047s
That's an interesting statement.I suggest the C library function result is the most plausible.
Ha!But I don't want to publish a million digits here given the current server problems
Well that might be possible, to do in a reasonable amount of time. Even in C.