From 127fa7139b2686709dab2ecebc882a3936eca8a6 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Tue, 13 Jan 2026 01:38:38 -0800 Subject: exponentiation word and a placeholder for integer printing Force-Push: yes Change-Id: Ie147f3010820ef740405bba9a932d1ae6067b49a --- quine.asm | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/quine.asm b/quine.asm index e37751f..de98b2b 100644 --- a/quine.asm +++ b/quine.asm @@ -3629,9 +3629,44 @@ defword emitstring, 0 dq docol, dup, stringlen, swap, sys_write, exit -defword emitinteger, 0 +; Although this could notionally be emitinteger for symmetry, it's +; well-known under the name dot and as a single period character, and that +; name participates in conventions for names of other things. So, we go with +; it. +; +; Unlike Jonesforth, we do not have a global "base" variable, and this word +; does not change its behavior depending on that value. It's always base ten. +; +; This is an extremely inefficient implementation, but on the plus side, +; doing that avoids having to think about any sort of memory management or +; recursion, and lets us stick entirely with the trivial control-flow +; constructs we already have. +; +; In: +; integer +defword dot, 0 + ; TODO dq docol, drop, litstring, "(int goes here)", emitstring, exit +; In: +; base +; exponent +; Out: +; base to the power of exponent +defword pow, 0 + dq docol + dq lit, 1, swap + ; If the count of remaining powers is NOT equal to zero, the comparison will + ; return 0, which will cause the zbranch to skip the rest of the line. + dq dup, lit, 0, eq, zbranch, 5*8, drop, swap, drop, exit + ; (base, result so far, count of remaining powers) + dq lit, 1, sub, unroll3 + ; (updated count of remaining powers, base, result so far) + dq swap, dup, lit, 4, unroll + ; (base, updated count of remaining powers, result so far, base) + dq mul, swap + ; (base, updated result so far, updated count of remaining powers) + dq branch, -22*8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Development utilities ;;; @@ -5002,7 +5037,7 @@ defword show_source_between, 0 ; This is the non-lit branch. dq drop, branch, -29*8 ; This is the lit branch. - dq drop, dup, fetch, emitinteger, litstring, " ", emitstring + dq drop, dup, fetch, dot, litstring, " ", emitstring dq lit, 8, add dq branch, -41*8 -- cgit 1.4.1