From 421b56b401697dda99a7cfe402f16943ea094cd6 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Fri, 4 Jun 2021 18:27:33 +1000 Subject: [PATCH] adding the AGAIN control word --- adoc/p_again.adoc | 16 ++++++++++++++++ control.asm | 21 ++++++++++++++++++++- reference.adoc | 2 ++ wordindex.adoc | 1 + 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 adoc/p_again.adoc diff --git a/adoc/p_again.adoc b/adoc/p_again.adoc new file mode 100644 index 0000000..62e72f1 --- /dev/null +++ b/adoc/p_again.adoc @@ -0,0 +1,16 @@ +// control.asm: WORD p_again,'AGAIN',fasm + +anchor:p_again[] + +=== Word: AGAIN + +.... +Data stack: Compiling: ( -- a ) +.... + +"AGAIN" is an immediate function word that is used together with +<> and instead of <> to implement structured +execution control. AGAIN scans the datastack for the nearest preceding +BEGIN marker and lays out an unconditional branch from this point the +beginning of the block during execution. It thereafter performs the +<> compile action to end the block. diff --git a/control.asm b/control.asm index b6bfe0f..949f48c 100644 --- a/control.asm +++ b/control.asm @@ -165,4 +165,23 @@ p_end_ending: pop rbx next - + WORD p_again,'AGAIN',fasm,IMMEDIATE + ;; Compiling: ( a 0 * -- ) + ;; Lay out unconditional loop-back, then perform END action + mov rax,qword [p_here_DFA] + mov qword [rax],p_branch_CFA + mov qword [rax+8],0 + add rax,16 + mov qword [p_here_DFA],rax + mov rbx,rsp +p_again_loop: + cmp qword [rbx],0 + je p_ifagain_resolve + add rbx,8 + jmp p_ifagain_loop +p_again_resolve: + mov rbx,qword [rbx+8] + sub rbx,rax + mov qword [rax-8],rbx + mov rax,rsp + jmp p_end_scan diff --git a/reference.adoc b/reference.adoc index 1700ddf..7bf6815 100644 --- a/reference.adoc +++ b/reference.adoc @@ -41,6 +41,8 @@ include::adoc/p_Rgt.adoc[] include::separator.adoc[] include::adoc/p_abs.adoc[] include::separator.adoc[] +include::adoc/p_again.adoc[] +include::separator.adoc[] include::adoc/p_allot.adoc[] include::separator.adoc[] include::adoc/p_and.adoc[] diff --git a/wordindex.adoc b/wordindex.adoc index ebac853..2ffe08e 100644 --- a/wordindex.adoc +++ b/wordindex.adoc @@ -58,6 +58,7 @@ xref:p_2over[2OVER] {nbsp} xref:p_2swap[2SWAP] {nbsp} xref:p_abs[ABS] {nbsp} +xref:p_again[AGAIN] {nbsp} xref:p_allot[ALLOT] {nbsp} xref:p_and[AND] {nbsp} <> {nbsp} -- 2.39.2