From b42d8229a09103623f421937f217b8cc8609e06b Mon Sep 17 00:00:00 2001 From: kitty Date: Wed, 21 Jan 2026 16:17:18 +1100 Subject: move to STC forth, note on COMPILE, --- jefs.s | 8 ++++++++ readme.md | 27 ++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/jefs.s b/jefs.s index d698f13..eca2374 100644 --- a/jefs.s +++ b/jefs.s @@ -6,9 +6,17 @@ %assign __NR_brk 12 %assign __NR_exit 60 +section .bss +wstack_b: resq 2047 +wstack: resq 1 + section .text global _start _start: + ; init + mov r14, wstack + xor r15, r15 + mov rdi, 0 mov rax, __NR_exit syscall diff --git a/readme.md b/readme.md index 03b19f0..5d6ab77 100644 --- a/readme.md +++ b/readme.md @@ -5,18 +5,31 @@ if you use it and it breaks, too bad public domain -the plan right now is that this will be a DTC forth. -while an STC forth would be nice -(being able to mix assembly and forth would be nice) -having to manually compile in bytes would be annoying. -maybe one day i will do an STC forth... +the plan right now is that this will be an STC forth. +if this proves Too Complicated To Deal With the plan may be changed +to a DTC forth instead. ## forth registers there are a set of 'virtual registers' (see moving forth part 1) - W, the working register, is r11. - X, the secondary working register, is r12. -- IP, the instruction pointer, is r13. +- IP, the instruction pointer, is r13. (this will only be needed if we switch to DTC, otherwise this can be Y, a third general purpose register) - SP, the working stack pointer, is r14. -- RSP, the return stack pointer, is rsp. - TOS, the top of the stack, is r15. +- RSP, the return stack pointer, is rsp. + +on SP (r14): note that since TOS is kept in a register, +SP points to the *second* item in the stack. + +## miscellaneous notes and stuff + +### COMPILE, +this is an STC forth so when we compile a call we have to +write the bytes of a `call` in manually. +x86\_64 does not allow absolute jumps from an immediate address, +so a wonky but hopefully not too slow solution is to compile +`literal address → W` and then `call W`. It'll Be Fine? + +- `mov r11, [cfa] = `94 BB [CFA]` +- `call r11` = `41 FF D3` -- cgit v1.2.3