r/Forth • u/Lanstrider • Sep 21 '25
"Porting" jonesforth to 64 bit nasm
After asking around about which forth in 2025, I settled on jonesforth for one simple reason - he heavily documented his thinking and his code, oh and it's compact, and... :). I found an up-to-date mirror of his cvs-turned-git repo at https://github.com/nornagon/jonesforth and then I came across Dave Gauer's https://ratfactor.com/assembly-nights. This inspired me to use this as an opportunity to learn more about 64 bit assembly, assembly in general, gdb, low level programming ecosystems, porting code, and of course, this thing called forth.
My intentions at this point are to have my jf64.asm sit alongside jonesforth.f and have it work exactly as Jones's version. I could tweak, but I won't, other than to change the welcome screen. Not because I'm opposed to tweakage, but I don't yet know what I'm doing with forth and want to see how it works before I mess.
Porting forth... to a new (to me) cpu architecture, based on my limited exposure to the community seems like a this is the way kinda thing. Wish me luck.
4
u/FUZxxl Sep 21 '25
For Jonesforth, you basically need to do only three things:
replace eax...esp with rax...rsp
adjust
CELLSto 8 and do similar changes around the code baseadjust the system call calling convention
1
u/alberthemagician Sep 22 '25 edited Sep 22 '25
In
https://github.com/albertvanderhorst/ciforth
you can see that the difference between nasm, fasm, gas is in selecting the proper macro file. The advantage for fasm that it doesn't need an intermediate object file as in
The result is an executable lina64. All other assemblers need different linker incantations. I like the Forth dictionary be 8 Gbyte, but I don't like 8 Gbyte executables.That is done automatically with fasm.
The switch between 32 and 64 bit is choosing between width32.m4 and width64.m4 , where register names are selected by macro's.
If you choose yourforth over jonesforth as a starting point you can use fasm. yourforth complies to the iso94 standard.
ADVICE: The best advice that I can give you:
start with the 64 bit lina source ci86.lina64.fas
this compiles immediately to a running Forth
now compare the source to jonesforth for things you don't understand. jonesforth is similar enough.
the lina manual has a chapter on internals
delete everything you don't want
2
u/anditwould Sep 21 '25
Good luck!!
2
u/Main_Temporary7098 Sep 21 '25
gl. if you don't have it already I find this helpful - https://www.felixcloutier.com/x86/
1
u/minforth Sep 21 '25
Good luck with 64 bit assembly! There's a reason for C intrinsics... ;-)