This is an entry in my developer’s log series written between December 2021 and August 2022 (started project in September). I wrote these as I completed my port of the JONESFORTH assembly language Forth interpreter.
Okay, EMIT is written. Now to test it, I'll push an ASCII character value on the stack and call it. (gdb) c Continuing. 65 EMIT A No way...it works! How about pushing "Foo" onto the stack and emitting it all at once: 70 111 111 EMIT EMIT EMIT ooF Ha ha, "oof" is right. The first of, no doubt, many out-of-order mistakes. 111 111 70 EMIT EMIT EMIT Foo Now how about compiling a word? : star 42 EMIT ; star * And the true test: can I compile a word using the new word? : 3star star star star ; 3star *** Wow. I have a FORTH! JonesFORTH defines a bunch of words in assembly (mostly for speed - there's some theoretical minimum core of FORTH words from which all the others could be defined, but assembly's gonna be faster. So what I'll do is start implementing those. I'll try to test them all with EMIT output because that's more fun than examining registers. But I doubt we're done with GBD just yet. - - - - - Next night: wait a second! I just realized this is an opportunity to demonstrate that this thing is now capable of executing the "Hello world" greeting. - - - - - Next night: okay, I fell asleep entering my hello world last night. Let's give it another shot. :-) : h1 111 108 108 101 72 EMIT EMIT EMIT EMIT EMIT ; h1 Hello : h2 100 108 114 87 EMIT EMIT EMIT EMIT EMIT ; h2 Wrld Oops! LOL, I left out the 'o'. Well, I am spelling this out backwards in ASCII... So, with Forth, I can just redefine the h2 word and the new definition will replace the broken one... : h2 100 108 114 111 87 EMIT EMIT EMIT EMIT EMIT ; h2 World That's better. And I'll make a word for space: : s 32 EMIT ; s And now for my triumphant Hello World: h1 s h2 Hello World TADA!