/
        PROGRAM cmpw
        optimize with r2

a1:     .asciz '	tst #@1'
a2:     .asciz '	cmp #@1,#@2'
a3:     .asciz '	clr -(sp)'
a4:     .asciz 'LET (sp) = <#@1>'
a5:     .asciz 'LET (sp) = #@1'
a6:     .asciz 'LET (sp) = <#@2>'
a7:     .asciz 'LET (sp) = #@2'
a8:     .asciz '	cmp (sp)+,#@2'
a9:     .asciz '	cmp #@1,(sp)+'
a10:    .asciz '	cmp (sp)+,(sp)+'
        .even
;+
; Compare word arguments (cmp. x,y) but x and y may be expressions, functions
; or other stuff.
;-

        AUTO p1 p2
FUNCTION cmpw[s,t,n,l]
        LET p1 = ifrec1[fndstr[t,#2]]
        LET p2 = ifrec1[fndstr[t,#3]]
        IF p1 = #0  AND p2 = #0
;            . exstat["xx <#@1> <#@2> 1",&s,#0]
            LET r4 = fndstr[t,#3]
            IFB (r4) NE #0
                IFB (r4) = #2  AND  1(r4) = #'#  AND  2(r4) = #'0
                    LET r3 = #a1
                ELSE
                    LET r3 = #a2
                FI
                . exstat[r3,&s,#0]
            FI
        ELSEIF p1 = #1  AND p2 = #0
;            . exstat["xx <#@1> <#@2> 2",&s,#0]
            call prm1
            . exstat[#a8,&s,#0]
        ELSEIF p1 = #0  AND p2 = #1
;            . exstat["xx <#@1> <#@2> 3",&s,#0]
            call prm2
            . exstat[#a9,&s,#0]
        ELSEIF p1 = #1  AND p2 = #1
;            . exstat["xx <#@1> <#@2> 4",&s,#0]
            call prm2
            call prm1
            . exstat[#a10,&s,#0]
        FI
        RET


prm2:
        . exstat[#a3,&s,#0]
        LET r4 = exjsr[#etst,"#@2",&s]
        IF r4 = #0
            LET r3 = #a6
        ELSE
            LET r3 = #a7
        FI
        . exstat[r3,&s,#0]
        rts pc


prm1:
        . exstat[#a3,&s,#0]
        LET r4 = exjsr[#etst,"#@1",&s]
        IF r4 = #0
            LET r3 = #a4
        ELSE
            LET r3 = #a5
        FI
        . exstat[r3,&s,#0]
        rts pc

FUNCTION etst[s,t,n,l]                        ;expression tester
        IF n GE #3
            LET r4 = fndstr[t,#2]
            SELECT case 1(r4) of
            CASEB #'+ OR
            CASEB #'- OR
            CASEB #'* OR
            CASEB #'/
                RET #1
            ESAC
        FI
        RET #0
        .end
