colorful rat Ratfactor.com > Dave's Repos

nasmjf

A NASM assembler port of JONESFORTH
git clone http://ratfactor.com/repos/nasmjf/nasmjf.git

nasmjf/devlog/log12.txt

Download raw file: devlog/log12.txt

1 Okay, EMIT is written. Now to test it, I'll 2 push an ASCII character value on the stack 3 and call it. 4 5 (gdb) c 6 Continuing. 7 65 EMIT 8 A 9 10 No way...it works! 11 12 How about pushing "Foo" onto the stack and 13 emitting it all at once: 14 15 70 111 111 EMIT EMIT EMIT 16 ooF 17 18 Ha ha, "oof" is right. The first of, no doubt, 19 many out-of-order mistakes. 20 21 111 111 70 EMIT EMIT EMIT 22 Foo 23 24 Now how about compiling a word? 25 26 : star 42 EMIT ; 27 star 28 * 29 30 And the true test: can I compile a word using the 31 new word? 32 33 : 3star star star star ; 34 3star 35 *** 36 37 Wow. I have a FORTH! 38 39 JonesFORTH defines a bunch of words in assembly (mostly 40 for speed - there's some theoretical minimum core of 41 FORTH words from which all the others could be defined, 42 but assembly's gonna be faster. 43 44 So what I'll do is start implementing those. I'll try 45 to test them all with EMIT output because that's more fun 46 than examining registers. But I doubt we're done with 47 GBD just yet. 48 49 - - - - - 50 51 Next night: wait a second! I just realized this is an 52 opportunity to demonstrate that this thing is now capable 53 of executing the "Hello world" greeting. 54 55 - - - - - 56 57 Next night: okay, I fell asleep entering my hello world 58 last night. Let's give it another shot. :-) 59 60 : h1 111 108 108 101 72 EMIT EMIT EMIT EMIT EMIT ; 61 h1 62 Hello 63 : h2 100 108 114 87 EMIT EMIT EMIT EMIT EMIT ; 64 h2 65 Wrld 66 67 Oops! LOL, I left out the 'o'. Well, I am spelling 68 this out backwards in ASCII... 69 70 So, with Forth, I can just redefine the h2 71 word and the new definition will replace the 72 broken one... 73 74 : h2 100 108 114 111 87 EMIT EMIT EMIT EMIT EMIT ; 75 h2 76 World 77 78 That's better. And I'll make a word for space: 79 80 : s 32 EMIT ; 81 s 82 83 And now for my triumphant Hello World: 84 85 h1 s h2 86 Hello World 87 88 TADA!