fmt: add word ".x" and fix .X to 4 chars output
Simpler code, more predictable output.
This commit is contained in:
parent
7390cb18ed
commit
7df7416e9e
@ -193,10 +193,11 @@ core.
|
|||||||
number parsing. By default, (parse).
|
number parsing. By default, (parse).
|
||||||
(print) a -- Print string at addr a.
|
(print) a -- Print string at addr a.
|
||||||
. n -- Print n in its decimal form
|
. n -- Print n in its decimal form
|
||||||
.X n -- Print n in its hexadecimal form. In hex, numbers
|
.x n -- Print n's LSB in hex form. Always 2 characters.
|
||||||
|
.X n -- Print n in hex form. Always 4 characters. Numbers
|
||||||
|
are never considered negative. "-1 .X" --> ffff
|
||||||
." xxx" -- *I* Compiles string literal xxx followed by a call
|
." xxx" -- *I* Compiles string literal xxx followed by a call
|
||||||
to (print)
|
to (print)
|
||||||
are never considered negative. "-1 .X -> ffff"
|
|
||||||
C< -- c Read one char from buffered input.
|
C< -- c Read one char from buffered input.
|
||||||
EMIT c -- Spit char c to output stream
|
EMIT c -- Spit char c to output stream
|
||||||
IN> -- a Address of variable containing current pos in input
|
IN> -- a Address of variable containing current pos in input
|
||||||
|
34
forth/fmt.fs
34
forth/fmt.fs
@ -1,7 +1,6 @@
|
|||||||
( requires core, parse )
|
( requires core, parse )
|
||||||
|
|
||||||
( TODO FORGET this word )
|
: _
|
||||||
: PUSHDGTS
|
|
||||||
999 SWAP ( stop indicator )
|
999 SWAP ( stop indicator )
|
||||||
DUP 0 = IF '0' EXIT THEN ( 0 is a special case )
|
DUP 0 = IF '0' EXIT THEN ( 0 is a special case )
|
||||||
BEGIN
|
BEGIN
|
||||||
@ -16,7 +15,7 @@
|
|||||||
( that "0 1 -" thing is because we don't parse negative
|
( that "0 1 -" thing is because we don't parse negative
|
||||||
number correctly yet. )
|
number correctly yet. )
|
||||||
DUP 0 < IF '-' EMIT 0 1 - * THEN
|
DUP 0 < IF '-' EMIT 0 1 - * THEN
|
||||||
PUSHDGTS
|
_
|
||||||
BEGIN
|
BEGIN
|
||||||
DUP '9' > IF DROP EXIT THEN ( stop indicator, we're done )
|
DUP '9' > IF DROP EXIT THEN ( stop indicator, we're done )
|
||||||
EMIT
|
EMIT
|
||||||
@ -25,24 +24,21 @@
|
|||||||
|
|
||||||
: ? @ . ;
|
: ? @ . ;
|
||||||
|
|
||||||
: 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' +
|
DUP 9 > IF 10 - 'a' +
|
||||||
ELSE '0' + THEN ( q d )
|
ELSE '0' + THEN
|
||||||
SWAP ( d q )
|
|
||||||
AGAIN
|
|
||||||
;
|
;
|
||||||
|
|
||||||
: .X ( n -- )
|
|
||||||
( For hex display, there are no negatives )
|
( For hex display, there are no negatives )
|
||||||
PUSHDGTS
|
|
||||||
BEGIN
|
: .x
|
||||||
DUP 'f' > IF DROP EXIT THEN ( stop indicator, we're done )
|
256 MOD ( ensure < 0x100 )
|
||||||
EMIT
|
16 /MOD ( l h )
|
||||||
AGAIN
|
_ EMIT ( l )
|
||||||
|
_ EMIT
|
||||||
|
;
|
||||||
|
|
||||||
|
: .X
|
||||||
|
256 /MOD ( l h )
|
||||||
|
.x .x
|
||||||
;
|
;
|
||||||
|
Loading…
Reference in New Issue
Block a user