: constant create 4 x, does> @ ;
: variable create 4 x, ;

h @ $20000 + constant asmbase
asmbase variable offset
: db, offset @ ! offset @ 1 + offset ! ;
: dup offset @ $83 db, $ee db, $04 db, $89 db, $06 db, $c3 db, call, ; 
: code[ offset @ dup offset ! ;
: ]code $c3 db, call, asmbase offset ! ;

: drop code[ $ad db, ]code ;
: swap code[ $06 $87 2 bytes ]code ;
: rot swap code[ $04 $46 $87 3 bytes ]code ;
: not code[ $d0 $f7 2 bytes ]code ;
: * code[ $04 $c6 $83 $26 $f7 5 bytes ]code ;
: / code[ $fb $f7 $d2 $31 $ad $c3 $89 7 bytes ]code ;
: mod code[ $d0 $89 $fb $f7 $d2 $31 $ad $c3 $89 9 bytes ]code ;
: abs code[ $d8 $29 $d8 $31 $1f $fb $c1 $c3 $89 9 bytes ]code ;
: fill code[ $fb $e2 $47 $17 $89 $ad $c7 $89 $ad $c1 $89 $ad $c2 $89 14 bytes ]code ;
: abs code[ $d8 $29 $d8 $31 $1F $FB $C1 $c3 $89 9 bytes ]code ;
: and code[ $04 $c6 $83 $06 $23 5 bytes ]code ;
: =   code[ $04 $C6 $83 $C0 $19 $01 $E8 $83 $06 $2B 10 bytes ]code ;
: <   code[ $04 $C6 $83 $FF $FF $FF $FF $B8 $C3 $04
            $C6 $83 $C0 $31 $06 $7C $06 $3B 18 bytes ]code ;
: max code[ $04 $C6 $83 $06 $8B $06 $89 $02 $7C $06 $3B 11 bytes ]code ;
: min code[ $04 $C6 $83 $06 $8B $06 $89 $02 $7F $06 $3B 11 bytes ]code ;
: or  code[ $04 $C6 $83 $06 $0B ]code ;
: xor code[ $04 $C6 $83 $06 $33 ]code ;

: ( ') word drop drop ;

( Key Constants )
-1 constant true
 0 constant false
asmbase $10000 + variable pad-area

( Numeric Bases )
: hex 16 base ! ;
: decimal 10 base ! ;
: octal 8 base ! ;
: binary 2 base ! ;

( The , words are used to allocate single bytes at here )
: here h @ ;
: , 4 x, ;
: 1, 1 x, ;
: 2, 2 x, ;
: 3, 3 x, ;

( Stack Words )
: -rot rot rot ;
: over swap dup -rot ; 
: nip swap drop ;
: tuck swap over ;
: 2dup over over ;
: 2drop drop drop ;

( Math Words )
: neg -1 * ;
: - neg + ;
: /mod over over / rot rot mod ;
: */ * / ;
: */mod * /mod ;

( Conditionals )
: <> = not ;
: > swap < ;

( Improved Variable Words )
: off false swap ! ;
: on true swap ! ;
: +! swap over @ + swap ! ;
: ++ 1 +! ;
: -- -1 +! ;

( Alignment and Storage Allocation )
: pad pad-area @ ;
: align 0 here 4 mod x, ;
: allot x, ;
: cell+ 4 + ;
: cells 4 * ;
: char+ 1 + ;
: chars 1 * ;
: array create cells allot does> swap cells + ;

( Generate stacks at runtime )
: stack: create cells dup here cell+ dup , + , allot ;
: push 1 cells over +! @ ! ;
: pop dup @ @ -1 cells rot +! ;

( Return Stack [minimal implementation] )
10 stack: rsp
: >r rsp push ;
: r> rsp pop ;
: r@ rsp pop dup rsp push ;

( String Words )
: " '" word ;
: string: create , , does> dup @ swap cell+ @ swap ;
: count dup >r c@ r> char+ swap ;
: place over over >r >r char+ swap cmove r> r> c! ;
: copy$ >r count swap 1 - swap r> swap cmove ;
