code 'bytes', bytes
   upop C
.1 push C
   embed 'db,'
   pop C
   loop .1
next

code 'call,', $call
     mov ebx, TOS
     drop
     call ebx
next

; ( source dest count -- )
code 'cmove', $cmove
              mov C,TOS
              drop
	mov W,TOS
              drop
	push PSP
	mov PSP,TOS
.1            mov edx, [PSP] 
              mov [W], edx
              inc W
              inc PSP
              loop .1
	pop PSP
              drop
next

code '@', fetch
     mov TOS,[TOS]
next

code '+',plus
  add TOS,[PSP]			; +
  add PSP,byte 4
next

code '.', print
 push edx
 push W
 mov W,PSP   		 ;W = buffer (in stack space)
 sub W,4
 or TOS,TOS              ;Negative?
 jns .1
 neg TOS
 upsh '-'
 call emit
.1                       ;Convert
 xor edx,edx
 div dword [base]
 add dl,'0'
 cmp dl,'9'
 jbe .2
 add dl,7+32
.2
 dec W
 mov [W],dl
 or TOS,TOS
 jnz .1
 mov TOS,W            ;Print
 upsh PSP
 sub TOS,W            ;# of digits
 call type
 pop W
 pop edx
 upsh ' '				;  And add one space after
 call emit				;  the number
next

code 'rot', rot
	xchg TOS,[PSP]
	xchg TOS,[PSP+4]
next

s_dest dd 0
code 's', s
      upop [s_dest]
      mov [tp],dword tib
.0	call key
	cmp al,10
	je .done
	  xchg W,[tp]
	  stosb
	  xchg [tp],W
	  call emit
	  jmp short .0
.done	push C	;move string to a safer place...
	push W
	mov W,[s_dest]
	mov TOS,W	;push addr
	dup
	push PSP
	mov C,[tp]
	mov PSP,tib
	sub C,PSP
	mov TOS,C	;push length
	rep movsb
	pop PSP
	pop W
	pop C
      call cr
next

code '!', store
  upop edx			; !
  mov [edx],TOS
  drop
next

code 'type',type
	push ebx
	push C
	upop C
	upop ebx
	or C,C              ; Is the count zero?
	jz .done                ; If so, we can exit
.1	push C                ; store the count
	dup                     ; Duplicate it
	xor TOS,TOS             ; Filter out junk bits
	mov al,[ebx]            ; Obtain the byte to show
	inc ebx                 ; increment to the next byte
	call emit               ; Show the character
	pop C                 ; Restore the count
	loop .1                 ; Loop, decrementing the count
.done	pop C
	pop ebx
next

code 'word',$word
        mov W,[tin]           ; Pointer into TIB
        mov C,[tp]
        sub C,W
        inc C
        repe scasb
        dec W
        inc C
        dup
        mov [PSP],W           ;a
        repne scasb
        mov TOS,W
        dec TOS
        sub TOS,[PSP]           ;n
        mov [tin],W
next

code 'words',words
        push ebx
        mov ebx, [last]
.1	  mov ebx,[ebx]
	  or ebx,ebx
	  jz .end
	  dup
	  lea TOS,[ebx+8]
      dup
	movzx TOS,byte [TOS]
	inc dword [PSP]
	  call $type
	  upsh 32
        call emit
	  jmp short .1
.end	pop ebx
next
