etherforth_logo

Node 509

This node is used as an interpreter stack.

Source code

editor node 409 node 509
509 stack
10* 00 n-m dup 2* 2* . + 2* ;
16* 02 n-m dup 2* 2* 2* 2* ;
mul 04 @p push ; 05 0 ,
dec 06 0 '10* 5 'mul a! ! -10 15 'dig? a! ! ;
hex 0D 2 '10* 5 'mul a! ! -16 15 'dig? a! ! ;
dig? 14 c -10 over . + -if drop ;
then drop drop begin drop @b -until !b -d-- ;
num! 1C dup dup or @b if dec else hex then
begin -if - !b ; then dig? push mul pop . + @b end
num@ 27 n !b ; 28

init down b! -d-- ; 2B

1 r 0 d 0 ether

Definitions

10*
Multiply T by 10.
16*
Multiply T by 16.
mul
Deferred word for multiplication. It holds address of either 10* or 16*.
dec
Set decimal conversion by pointing mul to 10* and setting the constant in dig? to -10.
hex
Set hexadecimal conversion by pointing mul to 16* and setting the constant in dig? to -16.
dig?
If character c is valid digit in the current base (hex or dec) then return, else discard all characters till eow signal, then return negative as failed flag and jump back to DOWN.
num!
Set zero on stack, read the first character. If zero, then set base to hex, otherwise to decimal. Convert characters to number, checking each new char with dig? until negative eow flag received or non-digit character. Return positive ok flag if all chars ok till eow and return.
num@
Send top of stack to 409.
init
Set register B, and jump to DOWN.

Description