;
; group i, test 2
;
; and.16
;

m4_include(..\tmacros.h)

INIT_TEST(h,0x02)

; declare symbols here
SYM(hop)
SYM(d1)
SYM(d2)
SYM(d3)
SYM(d4)
SYM(d5)
SYM(d6)
SYM(d7)
SYM(next0)
SYM(next1)
SYM(next2)
SYM(next3)
SYM(next4)
SYM(next5)
SYM(next6)
SYM(next7)
SYM(next8)
SYM(next9)
SYM(next10)
SYM(next11)
SYM(next12)
SYM(next13)
SYM(next14)
SYM(next15)

    br	hop

    ; Declare data here.  Format is:
    ;	op1
    ;	op2
    ;	expected a result
    ;	expected flags result V S C Z

d1:
    defw    0xff00
    defw    0x0100
    defw    0x0100
    defw    0x0000
d2:
    defw    0x0000
    defw    0x0000
    defw    0x0000
    defw    0x0100
d3:
    defw    0xf000
    defw    0x0f00
    defw    0x0000
    defw    0x0001
d4:
    defw    0x8000
    defw    0x8100
    defw    0x8000
    defw    0x0004

hop:
; Begin test here

SUBTEST(1)
;   <op>.16  a,u16(dp)
    ld.16   a,d1
    lea	    a,-555(a)
    copy    dp,a
    ld.16    a,555(dp)
    and.16   a,555+2(dp)
    push    msw
    cmpb.eq.16	a,555+4(dp),next0
    FAIL
next0:
    pop	    a
    and.16   a,0x5
    cmpb.eq.16	a,555+6(dp),next1
    FAIL
next1:

SUBTEST(2)
;   <op>.16  a,u8(sp) # Don't forget to reset SP!
    ld.16   a,d2
    lea	    a,-55(a)
    copy    sp,a
    ld.16    a,55(sp)
    and.16   a,55+2(sp)
    cmpb.eq.16	a,55+4(sp),next2
    FAIL
next2:
next3:
    ld.16   a,0x7000
    copy    sp,a

SUBTEST(3)
;   <op>.16  a,u8(b)
    ld.16   a,d3
    lea	    b,-5(a)
    ld.16    a,5(b)
    and.16   a,5+2(b)
    push    msw
    cmpb.eq.16	a,5+4(b),next4
    FAIL
next4:
    pop	    a
    and.16   a,0x5
    cmpb.eq.16	a,5+6(b),next5
    FAIL
next5:

SUBTEST(4)
;   <op>.16  a,u16
    ld.16   a,d4
    lea	    b,-15(a)
    ld.16    a,15(b)
    and.16   a,0x8100
    push    msw
    cmpb.eq.16	a,15+4(b),next6
    FAIL
next6:
    pop	    a
    and.16   a,0x5
    cmpb.eq.16	a,15+6(b),next7
    FAIL
next7:

SUBTEST(6)
;   <op>.8  a,1
    ld.16    a,3331
    and.16   a,1
    push    msw
    cmpb.eq.16	a,0x0001,next10
    FAIL
next10:
    pop	a
    and.16   a,0x5
    cmpb.eq.16	a,0,next11
    FAIL
next11:

SUBTEST(7)
;   <op>.16  a,a
    ld.16    a,-5
    ld.16    b,-5
    and.16   a,b
    push    msw
    cmpb.eq.16	a,-5,next12
    FAIL
next12:
    pop	a
    and.16	a,0x5
    cmpb.eq.16	a,4,next13
    FAIL
next13:

SUBTEST(8)
;   <op>.16  a,b
    ld.16    a,0x1100
    ld.16    b,0x1000
    and.16   a,b
    push    msw
    cmpb.eq.16	a,0x1000,next14
    FAIL
next14:
    pop	a
    and.16   a,0x5
    cmpb.eq.16	a,0,next15
    FAIL
next15:



;   Finally, when done branch to pass
    END_TEST
