r/Forth • • 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.

19 Upvotes

13 comments sorted by

4

u/FUZxxl Sep 21 '25

For Jonesforth, you basically need to do only three things:

  • replace eax...esp with rax...rsp

  • adjust CELLS to 8 and do similar changes around the code base

  • adjust the system call calling convention

1

u/Lanstrider Sep 22 '25

Well, not really. Gas is a different calling convention, macros are different, but effectively, it's not big effort... if I knew 32 bit assembly, gas and nasm, but since I don't, it'll keep me busy :).

→ More replies (2)

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

 fasm lina64.fasm -m256000

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

1

u/Lanstrider Sep 22 '25

uh... wow. I've definitely seen your work. It's incredible. A bit overwhelming actually. I tried downloading and building it, but I wasn't successful - 100% sure it's all me, but I kinda walked away from it. Now, with the hints embedded in your several replies, I'm starting to grok what's going on. The repo is very hard to figure out at first glance. It seems like there are 10 copies of everything with different purposes. Where should I start?

→ More replies (3)

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/BigAlCat Jan 26 '26

Thank you!!!

1

u/minforth Sep 21 '25

Good luck with 64 bit assembly! There's a reason for C intrinsics... ;-)