From 6314c60ede8ff24115b265535b1029ca591902eb Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 17 Mar 2020 14:05:53 -0400 Subject: [PATCH] forth: add word ".X" --- apps/forth/core.fs | 24 +++++++++++++++++++++++- apps/forth/dictionary.txt | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/apps/forth/core.fs b/apps/forth/core.fs index 8578171..a29cebb 100644 --- a/apps/forth/core.fs +++ b/apps/forth/core.fs @@ -50,7 +50,7 @@ : / /MOD SWAP DROP ; : MOD /MOD DROP ; -( Format decimals ) +( Format numbers ) ( TODO FORGET this word ) : PUSHDGTS 999 SWAP ( stop indicator ) @@ -73,3 +73,25 @@ EMIT AGAIN ; + +: PUSHDGTS + 999 SWAP ( stop indicator ) + DUP 0 = IF '0' EXIT THEN ( 0 is a special case ) + BEGIN + DUP 0 = IF DROP EXIT THEN + 16 /MOD ( r q ) + SWAP ( r q ) + DUP 9 > IF 10 - 'a' + + ELSE '0' + THEN ( q d ) + SWAP ( d q ) + AGAIN +; + +: .X ( n -- ) + ( For hex display, there are no negatives ) + PUSHDGTS + BEGIN + DUP 'f' > IF DROP EXIT THEN ( stop indicator, we're done ) + EMIT + AGAIN +; diff --git a/apps/forth/dictionary.txt b/apps/forth/dictionary.txt index a83e812..fc86b72 100644 --- a/apps/forth/dictionary.txt +++ b/apps/forth/dictionary.txt @@ -147,6 +147,8 @@ KEY input, however, is direct. Regardless of the input buffer's state, KEY will return the next typed key. . n -- Print n in its decimal form +.X n -- Print n in its hexadecimal form. In hex, numbers + are never considered negative. "-1 .X -> ffff" EMIT c -- Spit char c to output stream IN> -- a Address of variable containing current pos in input buffer.