;
; group d, test 2
;
; 16-bit memory loads
;

m4_include(..\tmacros.h)

INIT_TEST(d,0x02)

; declare labels here
SYM(next0)
SYM(next1)
SYM(next2)
SYM(next3)
SYM(next4)
SYM(next5)
SYM(next6)
SYM(next7)

; Begin test here

SUBTEST(1)

;   DP w/ 16-bit offset

    ld.16   b,MEM0x8000_16
    lea	    a,-513(b)
    copy    dp,a
    ld.16    a,513(dp)
    cmpb.eq.16	a,0x8000,next0
    FAIL

next0:

SUBTEST(2)
    ld.16   a,MEM0x8000_16
    lea	    a,-513(a)
    copy    dp,a
    ld.16    b,513(dp)
    copy    a,b
    cmpb.eq.16	a,0x8000,next1
    FAIL

next1:

SUBTEST(3)

;   SP w/ 8-bit offset
;   NOTE: restore SP to 0x7000 after

    ld.16   a,MEM0x7FFF_16
    lea	    a,-122(a)
    copy    sp,a
    ld.16    a,122(sp)
    cmpb.eq.16	a,0x7fff,next2
    FAIL

next2:
    ld.16   a,0x7000
    copy    sp,a

SUBTEST(4)
    ld.16   a,MEM0x0001_16
    lea	a,-13(a)
    copy    sp,a
    ld.16    b,13(sp)
    copy    a,b
    cmpb.eq.16	a,0x0001,next3
    FAIL

next3:
    ld.16   a,0x7000
    copy    sp,a

SUBTEST(5)
    ld.16   a,MEM0x8000_16
    lea	    a,-100(a)
    ld.16    b,100(a)
    copy    a,b
    cmpb.eq.16	a,0x8000,next4
    FAIL

next4:

SUBTEST(6)
    ld.16   a,MEM0x8000_16
    lea	    b,-100(a)
    ld.16    b,100(b)
    copy    a,b
    cmpb.eq.16	a,0x8000,next5
    FAIL

next5:

SUBTEST(7)
    ld.16   b,MEM0x7FFF_16
    lea	    a,-44(b)
    ld.16    a,44(a)
    cmpb.eq.16	a,0x7fff,next6
    FAIL

next6:

SUBTEST(8)
    ld.16   b,MEM0x7FFF_16
    lea	    b,-44(b)
    ld.16    a,44(b)
    cmpb.eq.16	a,0x7fff,next7
    FAIL

next7:
    

;   Finally, when done branch to pass
    END_TEST
