\*
 *   ZEN 1.10  Flow of control
 *     C 1990  by Martin Tracy
 *             Last modified  1.1.90
 *\
ASSEMBLER

; Branch if false
ZBranch: ; ( f)
        or    bx,bx
        pop   bx
        jz    Branch
        add   si,2
        NEXT

; Branch always
Branch: ;
        mov   si,cs:[si]
        NEXT

; Begin DO ... LOOP or DO ... +LOOP
RDo:    ; ( n n2)
        pop   ax
        add   ax,8000h
        sub   bx,ax
        xchg  bp,sp
        push  ax
        push  bx
        xchg  bp,sp
        pop   bx
        NEXT

; End DO ... LOOP
RLoop:  ;
        inc   WORD PTR [bp]
        jno   Branch
Loop2:  add   si,2
_Undo:  add   bp,4
        NEXT

; End DO ... +LOOP
PLoop:  ; ( n)
        add   [bp],bx
        pop   bx
        jno   Branch
        jo    Loop2
        NEXT
END-CODE

\ Undoes one level of loop nesting
CODE UNLOOP ( ) \ CORE
        jmp   _Undo
END-CODE


\ Ends every colon definition
CODE EXIT ( ) \ CORE
        xchg  bp,sp
        pop   si
        xchg  bp,sp
        NEXT
END-CODE

\ Execute execution token w
CODE EXECUTE ( w) \ CORE
        xchg  ax,bx
        pop   bx
        jmp   ax
END-CODE


\ Does nothing.
CODE NOOP
        NEXT
END-CODE

\ Equivalent to @ EXECUTE
\ Does nothing if execution token is zero
CODE PERFORM ( a) \ EXT CORE
        mov   di,bx
        pop   bx
        mov   ax,[di]
        jmp   ax
        NEXT
END-CODE
