X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=main.fasm;h=25e48b4f69a9aa1daf2561f2a24230d3f848a771;hb=9c582d87bca4bce0aa889cad0bd200ee85512f78;hp=6bd525a8e3e84c5daa0de659457879e28940e544;hpb=b404f29caf2f82acc9fc4cd84e7247857878f7a8;p=rrq%2Frrqforth.git diff --git a/main.fasm b/main.fasm index 6bd525a..25e48b4 100644 --- a/main.fasm +++ b/main.fasm @@ -1,21 +1,79 @@ -; This is a program +; This is a forth interpreter format elf64 executable - entry main + entry main_code - segment readable executable - msg db 'hello world.' - db 10 - length = $ - msg +;;; ############################################################ +;;; The FORTH words + segment readable writable executable -main: - lea rsi,[msg] ; address of message - mov edx,length ; length od trdting +include 'machine.fasm' + + ;; PROGRAM_VERSION is the program version string + WORD program_version, 'PROGRAM_VERSION', marker + db length +program_version_string: + include 'version' + length = $ - program_version_string + + ;; MAIN is the program entry point + ;; ( -- ) + WORD_assembler main, "MAIN" + mov rsi,program_version_string ; address of string + mov edx,length ; length of string (cheating) mov edi,1 ; stdout mov eax,1 ; sys_write syscall + jmp terminate0_code -fini: + ;; TERMINATE0 terminates the program with code 0 + ;; ( -- ) + WORD_assembler terminate0, 'TERMINATE0' xor edi,edi mov eax,60 syscall + + ;; EXIT ends a forth code defintion, returning to caller + ;; ( -- ) + WORD_assembler exit, 'EXIT' + popr rsi + next + ;; MARKER is a word that pushes the address after itself, then exits + ;; ( -- p ) + WORD_assembler marker, 'MARKER' + push qword rsi + jmp exit_code + + ;; MARKER@ is a word that pushes a the value after itself, then exits + ;; ( -- v ) + WORD_assembler marker_get, 'MARKER@' + push qword [rsi] + jmp exit_code + + ;; DOFORTH begins a FORTH defintion + WORD_assembler doforth, 'DOFORTH' + pushr rsi + lea rsi, [rax + 8] + next + + ;; LIT is a word that pushes a the value after itself, then continues + ;; ( -- v ) + WORD_assembler lit, 'LIT' + push qword [rsi] + add rsi, 8 + next + + ;; HERE is a variable pointing to the free heap + WORD here, 'HERE', marker + dq heap_start ; initialise to first "free" data + + ;; WORDS is the list of words + WORD words, 'WORDS', marker + dq forth_tfa ; initialise to last forth word + + ;; FORTH is the last word of the VOCABULARY + WORD forth, 'FORTH', marker_get + dq forth_tfa + +heap_start: +