stacks  segment para stack
        dw      80h dup (?)
stacks	ends

prog    segment word
	assume	cs:prog, ds:prog, ss:stacks

xmsvec  dd      ?
handle  dw      ?
movsiz  dd      SRCLEN
shand   dw      0
soffs   dw      source, seg prog
thand   dw      ?
toffs   dw      0, 0

source  db      'Das ist ein '
        db      'Speicherbereich, der '
        db      'ins XMS verschoben werden '
        db      ' soll.'
SRCLEN  equ     $ - source
target  db      SRCLEN dup (?)

entry:  sti
        cld
        mov     ax,4300h
        int     2Fh
        cmp     al,80h
        jne     exit
        mov     ax,cs
        mov     ds,ax
        mov     ax,4310h
        int     2Fh
        mov     word ptr xmsvec,bx
        mov     word ptr xmsvec + 2,es

        mov     dx,1
        mov     ah,9
        call    xmsvec
        dec     ax
        jnz     exit

        mov     handle,dx
        mov     thand,dx
        mov     si,offset movsiz
        mov     ah,0Bh
        call    xmsvec
        dec     ax
        jnz     abort

        xor     ax,ax
        mov     soffs,ax
        mov     soffs + 2,ax
        xchg    ax,thand
        mov     shand,ax
        mov     toffs,offset target
        mov     toffs + 2,seg prog
        mov     ah,0Bh
        call    xmsvec
        dec     ax
        jnz     abort

        mov     dx,offset target
        mov     cx,SRCLEN
        mov     bx,1
        mov     ah,40h
        int     21h

abort:  mov     dx,handle
        mov     ah,0Ah
        call    xmsvec

exit:   mov     ax,4C00h
        int     21h

prog    ends
end     entry
