;
; Caller:       Microsoft Fortran
;
;               INTEGER*2 BOOL,X,X1,X2,X3
;               EXTERNAL BOOL
;
;               X = BOOL(X1,X2,X3)
;

ADDRx1          EQU     dword ptr [bp+14]   ; the last parameter in the
ADDRx2          EQU     dword ptr [bp+10]   ;  parameter list is nearest the
ADDRx3          EQU     dword ptr [bp+6]    ;  top of the stack

DGROUP          GROUP   _DATA

BOOL_TEXT       SEGMENT byte public 'CODE'
                ASSUME  cs:BOOL_TEXT,ds:DGROUP

                PUBLIC  BOOL
BOOL            PROC    far

                push    bp              ; push BP
                mov     bp,sp           ; establish stack addressing
                push    si              ; preserve SI and DI
                push    di

; parameters are passed by reference on the stack

                les     bx,ADDRx1
                mov     ax,es:[bx]      ; AX = x1

                les     bx,ADDRx2
                mov     cx,es:[bx]      ; CX = x2

                les     bx,ADDRx3
                mov     bx,es:[bx]      ; BX = x3

                and     bx,0Fh          ; ensure that 0 < BX < 0Fh
                shl     bx,1            ; BX = offset into table
                jmp     SubrTable[bx]
                
; result is returned in AX according to bits 0-3 of x3

L0000:  .
                .
                .

Lexit:          pop     di              ; restore registers
                pop     si
                pop     bp
                ret     12              ; discard parameters and exit

BOOL            ENDP

BOOL_TEXT       ENDS


_DATA           SEGMENT word public 'DATA'

SubrTable       DW      L0000,L0001,L0010,L0011,L0100,L0101,L0110,L0111
                DW      L1000,L1001,L1010,L1011,L1100,L1101,L1110,L1111

_DATA           ENDS

                END
