%title 'Test code every Pentium compatible disassembler should disassemble'
%subttl 'Copyright (c) 1998 Henrik Nebrin <wbinvd@mail.bip.net>'

        ideal
        p486
        nowarn  brk

segment _text para private 'code' use16
        assume  cs:@curseg
        org     0100h
start:
        retn
if 0
  @@modrm       equ     0CAh
else
  ifdef debug32
    @@modrm     equ     <0Dh,78h,56h,34h,12h>
  else
    @@modrm     equ     <0Eh,34h,12h>
  endif
endif

        ;Cyrix Opcodes
        db      0Fh,78h                 ;svdc
        db      0Fh,79h                 ;rsdc
        db      0Fh,7Ah                 ;svldt
        db      0Fh,7Bh                 ;rsldt
        db      0Fh,7Ch                 ;svts
        db      0Fh,7Dh                 ;rsts

        db      0Fh,36h                 ;rdshr
        db      0Fh,37h                 ;wrshr
        db      0Fh,38h                 ;smint
        db      0Fh,50h,@@modrm         ;paveb Pq,Qq
        db      0Fh,51h,@@modrm         ;paddsiw Pq,Qq
        db      0Fh,52h,@@modrm         ;pmagw Pq,Qq
        db      0Fh,54h,@@modrm         ;pdistib Pq,Qq
        db      0Fh,55h,@@modrm         ;psubsiw Pq,Qq
        db      0Fh,58h,@@modrm         ;pmvzb Pq,Qq
        db      0Fh,59h,@@modrm         ;pmulhrw Pq,Qq
        db      0Fh,5Ah,@@modrm         ;pmvnzb Pq,Qq
        db      0Fh,5Bh,@@modrm         ;pmvlzb Pq,Qq
        db      0Fh,5Ch,@@modrm         ;pmvgezb Pq,Qq
        db      0Fh,5Dh,@@modrm         ;pmulhriw Pq,Qq
        db      0Fh,5Eh,@@modrm         ;pmachirw Pq,Qq

        db      90h,90h,90h,90h,90h     ;if we're not disassembling cyrix

        ;AMD Opcodes and K3D opcodes
        db      0Fh,05h                 ;syscall
        db      0Fh,07h                 ;sysret
        db      0Fh,0FFh                ;ud (generate #ud)
        db      0Fh,0Dh,0C0h            ;prefetch
        db      0Fh,0Dh,0C8h            ;prefetchw
        db      0Fh,0Dh,0D0h            ;(actually, this should be memory,
        db      0Fh,0Dh,0D8h            ; not register)
        db      0Fh,0Dh,0E0h
        db      0Fh,0Dh,0E8h
        db      0Fh,0Dh,0F0h
        db      0Fh,0Dh,0F8h
        db      0Fh,0Eh                 ;femms
        n = 00h
        rept    0100h ;;almost all K3D opcodes
        db      0Fh,0Fh,@@modrm,n
        n = n + 1
        endm

        db      90h,90h,90h,90h,90h     ;if we're not disassembling cyrix

        ;Intel opcodes
        db      0Fh,34h                 ;sysenter
        db      0Fh,35h                 ;syscall
        db      0D6h                    ;salc
        db      0F1h                    ;int01
        db      0Fh,04h                 ;loadall (80286)
        db      0Fh,05h                 ;loadall (80286)
        db      0Fh,07h                 ;loadall (80386)
        db      0Fh,10h,@@modrm         ;umov Eb,Gb
        db      0Fh,11h,@@modrm         ;umov Ev,Gv
        db      0Fh,12h,@@modrm         ;umov Gb,Eb
        db      0Fh,13h,@@modrm         ;umov Gv,Ev
        db      0Fh,33h                 ;rdpmc
        db      0Fh,60h,@@modrm         ;punpcklbw Pq,Qd
        db      0Fh,61h,@@modrm         ;punpcklwd Pq,Qd
        db      0Fh,62h,@@modrm         ;punpckldq Pq,Qd
        db      0Fh,63h,@@modrm         ;packsswb Pq,Qq
        db      0Fh,64h,@@modrm         ;pcmpgtb Pq,Qq
        db      0Fh,65h,@@modrm         ;pcmpgtw Pq,Qq
        db      0Fh,66h,@@modrm         ;pcmpgtd Pq,Qq
        db      0Fh,67h,@@modrm         ;packuswb Pq,Qq
        db      0Fh,71h,0D0h,00h        ;psrlw Pq,Ib
        db      0Fh,71h,0E1h,01h        ;psraw Pq,Ib
        db      0Fh,71h,0F2h,02h        ;psllw Pq,Ib
        db      0Fh,72h,0D3h,03h        ;psrld Pq,Ib
        db      0Fh,72h,0E4h,04h        ;psrad Pq,Ib
        db      0Fh,72h,0F5h,05h        ;pslld Pq,Ib
        db      0Fh,73h,0D6h,06h        ;psrlq Pq,Ib
        db      0Fh,73h,0F7h,07h        ;psllq Pq,Ib
        db      0Fh,74h,@@modrm         ;pcmpeqb Pq,Qq
        db      0Fh,75h,@@modrm         ;pcmpeqw Pq,Qq
        db      0Fh,76h,@@modrm         ;pcmpeqd Pq,Qq
        db      0Fh,77h                 ;emms
        db      0Fh,0D1h,@@modrm        ;psrlw Pq,Qq
        db      0Fh,0D2h,@@modrm        ;psrld Pq,Qq
        db      0Fh,0D3h,@@modrm        ;psrlq Pq,Qq
        db      0Fh,0D5h,@@modrm        ;pmullw Pq,Qq
        db      0Fh,0E1h,@@modrm        ;psraw Pq,Qq
        db      0Fh,0E2h,@@modrm        ;psrad Pq,Qq
        db      0Fh,0E5h,@@modrm        ;pmulhw Pq,Qq
        db      0Fh,0F1h,@@modrm        ;psllw Pq,Qq
        db      0Fh,0F2h,@@modrm        ;pslld Pq,Qq
        db      0Fh,0F3h,@@modrm        ;psllq Pq,Qq
        db      0Fh,0F5h,@@modrm        ;pmaddwd Pq,Qq
        db      0Fh,0Bh                 ;ud1
        db      0Fh,40h,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,41h,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,42h,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,43h,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,44h,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,45h,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,46h,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,47h,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,48h,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,49h,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,4Ah,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,4Bh,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,4Ch,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,4Dh,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,4Eh,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,4Fh,@@modrm         ;cmovcc Gv,Ev
        db      0Fh,68h,@@modrm         ;punpckhbw Pq,Qq
        db      0Fh,69h,@@modrm         ;punpckhwd Pq,Qq
        db      0Fh,6Ah,@@modrm         ;punpckhdq Pq,Qq
        db      0Fh,6Bh,@@modrm         ;packssdw Pq,Qq
        db      0Fh,6Eh,@@modrm         ;movd Pq,Ed
        db      0Fh,6Fh,@@modrm         ;movq Pq,Qq
        db      0Fh,7Eh,@@modrm         ;movd Ed,Pq
        db      0Fh,7Fh,@@modrm         ;movq Qq,Pq
        db      0Fh,0B9h                ;ud2
        db      0Fh,0D8h,@@modrm        ;psubusb Pq,Qq
        db      0Fh,0D9h,@@modrm        ;psubusw Pq,Qq
        db      0Fh,0DBh,@@modrm        ;pand Pq,Qq
        db      0Fh,0DCh,@@modrm        ;paddusb Pq,Qq
        db      0Fh,0DDh,@@modrm        ;paddusw Pq,Qq
        db      0Fh,0DFh,@@modrm        ;pandn Pq,Qq
        db      0Fh,0E8h,@@modrm        ;psubsb Pq,Qq
        db      0Fh,0E9h,@@modrm        ;psubsw Pq,Qq
        db      0Fh,0EBh,@@modrm        ;por Pq,Qq
        db      0Fh,0ECh,@@modrm        ;paddsb Pq,Qq
        db      0Fh,0EDh,@@modrm        ;paddsw Pq,Qq
        db      0Fh,0EFh,@@modrm        ;pxor Pq,Qq
        db      0Fh,0F8h,@@modrm        ;psubb Pq,Qq
        db      0Fh,0F9h,@@modrm        ;psubw Pq,Qq
        db      0Fh,0FAh,@@modrm        ;psubd Pq,Qq
        db      0Fh,0FCh,@@modrm        ;paddb Pq,Qq
        db      0Fh,0FDh,@@modrm        ;paddw Pq,Qq
        db      0Fh,0FEh,@@modrm        ;paddd Pq,Qq

        db      0Fh,01h,0E0h            ;smsw ax
        db      66h,0Fh,01h,0E0h        ;smsw eax
        db      0C0h,0F0h,02h           ;shl al,immediate
        db      0C1h,0F0h,03h           ;shl ax,immediate
        db      66h,0C1h,0F0h,04h       ;shl eax,immediate
        db      0D0h,0F0h               ;shl al,1
        db      0D1h,0F0h               ;shl ax,1
        db      66h,0D1h,0F0h           ;shl eax,1
        db      0D2h,0F0h               ;shl al,cl
        db      0D3h,0F0h               ;shl ax,cl
        db      66h,0D3h,0F0h           ;shl eax,cl
        db      0F6h,0C8h,01h           ;test al,imm8
        db      0F7h,0C8h,00h,01h       ;test ax,imm16
        db      66h,0F7h,0C8h,00h,00h,00h,01h;test eax,imm32

        call    ax
        call    eax
        jmp     ax
        jmp     eax
        call    word ptr ds:0
        call    dword ptr ds:0
        db      66h
        call    word ptr ds:0
        call    fword ptr ds:0
        jmp     word ptr ds:0
        jmp     dword ptr ds:0
        db      66h
        jmp     word ptr ds:0
        jmp     fword ptr ds:0
        dw      0E0DCh,0E8DCh,0F0DCh,0F8DCh
        dw      0E0DEh,0E8DEh,0F0DEh,0F8DEh

        mov     al,[ecx*8-00000003h]
        mov     al,[edx*8-00000005h]
        mov     al,[ebx*8+00000103h]
        mov     al,[ebp*8+00000105h]

        esc     00h,eax
        fmul    st,st(1)
        fcomp   st(1)
        fcomp   st(6)

        esc     09h,[eax*8]
        fadd    dword ptr gs:[esp+eax*8-80000000h]
        fucom   st(0)
        db      0DFh,0C0h,90h,90h,90h,90h
        esc     09h,[eax*8]
        call    word ptr ds:[large 00000000]
        call    dword ptr ds:[large 00000000]
        db      66h
        call    word ptr ds:[large 00000000]
        call    fword ptr ds:[large 00000000]
        mov     eax,12345678h
        xlat    byte ptr gs:[ebx]
        mov     cx,[ebp+edi*8+0DEADBEEFh]
        mov     cx,[ebp+edi*8+0DEADBEEFh]
        mov     cx,[ebp+edi*8+0BEEFh]
        mov     cx,[ebp+edi*8+0BEEF0000h]
        mov     cx,[ebp+edi*8+00BEEF00h]
        mov     al,[bp+7Bh]
        mov     al,[bp-7Bh]
        mov     al,[bp+7Dh]
        mov     al,[bp-7Dh]
        mov     al,[bp+7FFBh]
        mov     al,[bp-7FFBh]
        mov     al,[bp+7FFDh]
        mov     al,[bp-7FFDh]
        mov     al,[ebp+7FFFFFFBh]
        mov     al,[ebp-7FFFFFFBh]
        mov     al,[ebp+7FFFFFFDh]
        mov     al,[ebp-7FFFFFFDh]
        mov     al,[bp]
        mov     al,0FFh
        mov     al,0FDh
        mov     al,0FBh
        db      66h
        mov     [1234h],gs
        xlatb
        xlat    byte ptr ss:[ebx]
if 01
;        fucom   st(0),st
        fucom   st(0)
        esc     09h,[eax*8]
        esc     19h,[eax]
        esc     1Ch,[12345678h]
        esc     1Eh,[bx]
        esc     29h,[bp]
        esc     2Dh,[esp]
        esc     39h,[ebp]
endif
        mov     cx,[small 0]
        mov     cx,[large 0]
        mov     ax,[bx]
        mov     cx,[ebx]
        mov     ax,[bp+di+0DEADh]
        mov     cx,[ebp+edi*8+0DEADBEEFh]
        mov     ax,[eax*8]
n = 0
        rept 40h
        esc     n,gs:[esp+eax*8+80000000h+n]
        n = n + 1
        endm
n = 0
        rept 40h
        esc     n,ax
        esc     n,cx
        esc     n,dx
        esc     n,bx
        esc     n,sp
        esc     n,bp
        esc     n,si
        esc     n,di
        n = n + 1
        endm

        rep movs byte ptr es:[di],byte ptr fs:[si]
        db      66h
        mov     [1234h],gs
        mov     es:[0000],ax
        mov     cs:[0000],cx
        mov     ss:[0000],dx
        segds
        mov     ds:[0000],bx
        mov     fs:[0000],sp
        mov     gs:[0000],bp
        mov     si,es:[0000]
        mov     di,cs:[0000]
        mov     eax,ss:[0000]
        segds
        mov     ecx,ds:[0000]
        mov     edx,fs:[0000]
        mov     ebx,gs:[0000]

        lock xchg ax,[1234q]
        repnz scasb
        mov     [1234h],cs
        db      66h
        mov     [1234h],gs
        mov     ss,[1234h]
        db      66h
        mov     fs,[1234h]
        setne   cl
        setne   [1234o]
        mov     word ptr ds:[0000],1234h
        call    $+8000h
        jmp     $+8000h
        mov     [si],al
        mov     al,[bp-03]
        mov     al,[bp-05]
        mov     al,[bp+0103h]
        mov     al,[bp+0105h]
        mov     al,[ebp*8-3]
        mov     al,[ebp*8-5]
        mov     al,[ebp*8+00000103h]
        mov     al,[ebp*8+00000105h]
        mov     al,[ebp+0FFFFFFFDh]
        mov     al,[ebp+0FFFFFFFBh]
        mov     al,[ebp+4FFFFFFDh]
        mov     al,[ebp+6FFFFFFBh]

        mov     eax,[eax*2+00000123h]
        mov     ecx,[ecx*2+00000001h]
        mov     edx,[edx*2+00000000h]
        mov     ebx,[ebx]
        mov     esp,[esp]
        mov     ebp,[ebp]
        mov     esi,[esi]
        mov     edi,[edi]

        mov     eax,[ebp*8]
        lea     cx,[eax*4]
        mov     esp,[small 1234h]
        mov     cx,[large 12345678h]
        mov     eax,[ebp*8]
        lea     cx,[eax*4]
        mov     eax,[esp+ebp*8]
        lea     cx,[ecx+eax*4]
        mov     ecx,[esp]
        mov     ecx,[esp+01]
        mov     ecx,[esp+1000h]
        mov     [esi],ss
        mov     ax,[bx+si+01]
        mov     cx,[bx+di+01]
        mov     dx,[bp+si+01]
        mov     bx,[bp+di+01]
        mov     sp,[bp+01]
        mov     bp,[bx+01]
        mov     si,[si+01]
        mov     di,[di+01]
        mov     al,[bp-03]
        mov     al,[bp-05]
        ror     eax,08h
        sub     word ptr ds:[ebx+8FFFFFFDh],8FFBh
        sub     dword ptr ds:[esi+9FFFFFFBh],9FFFFFFDh
        sub     cx,0EF1Bh
        sub     word ptr ds:[321],001Dh
        sub     ecx,00ABh
        sub     dword ptr ds:[ecx],000000ADh
        sub     ebx,0FFFFFFFDh
        sub     ebp,0FFFFFFFBh
        mov     [8000h],al
        mov     [0A000h],al
        mov     [0800h],al
        mov     [0A00h],al
        mov     [0080h],al
        mov     [00A0h],al
        mov     [0008h],al
        mov     [000Ah],al
        call    large far ptr 1234h:56789ABCh
        call    small far ptr 8888h:7777h
        movsx   ecx,byte ptr gs:[0000h]
        movsx   esi,word ptr fs:[1234h]

        mov     eax,cr0
        mov     cr2,ecx
        mov     edx,dr1
        mov     dr7,ebx
        mov     esp,tr3
        mov     tr6,ebp
        mov     esi,cr0
        mov     cr3,edi
        or      ecx,12345678h
        lar     cx,dx
        imul    sp,[bx+1234h]
        bsr     edi,[0000]
        movsx   sp,al
        movzx   edi,byte ptr ss:[esi*2+00000000]
        movsx   esp,sp
        movzx   edi,word ptr ss:[esi*2+00000000]
        rol     word ptr ds:[0000h],01h
        shl     eax,01h
        rcr     word ptr ds:[esp],cl
        sar     edx,cl
        mov     ecx,12345678h
        or      eax,12345678h
        test    eax,12345678h
        in      ax,21h
        in      eax,21h
        mov     ah,20h
        mov     bh,21h
        add     ecx,ecx
        cmp     [0000h],sp
        cmpxchg [0000h],bp
        bt      [0000h],esi
        xadd    esp,ebp
        db      0Fh,5Bh
        db      0Fh,72h
        rol     dh,01h
        shr     byte ptr fs:[0000h],01h
        rcr     cl,cl
        sar     byte ptr gs:[0000h],cl
        mov     ax,cs
        mov     [esp],ss
        mov     fs,cx
        mov     gs,[bp]
        sbb     cl,ss:[0000h]
        xor     ah,dh
        out     20h,eax
        out     20h,ax
        out     20h,al
        add     al,12h
        in      al,21h
        or      al,0Fh
        and     [0000],dl
        cmpxchg [0000],dh
        mov     al,[0000]
        mov     ax,[0000]
        mov     eax,[0000]
        mov     [0000],al
        mov     [0000],ax
        mov     [0000],eax
        les     eax,[0000]
        lfs     sp,[esp+ebp]
        bound   esp,[0000]
        lea     sp,[bp+si]
        mov     byte ptr ds:[bx],12h
        rcl     byte ptr ds:[0000],02h
        test    byte ptr ds:[esi],21h
        add     dword ptr ds:[esp],-2
        xor     cx,-3
        xchg    sp,ax
        xchg    edi,eax
        rol     ecx,10h
        btc     esp,03h
        mov     word ptr ds:[bx],0000h
        mov     dword ptr ds:[esp+ebp],0BADCAFEh
        in      al,dx
        in      ax,dx
        in      eax,dx
        out     dx,al
        out     dx,ax
        out     dx,eax
        jmp     $+8000h
        jmp     far ptr 1234h:5678h
        call    $+8000h
        call    far ptr 1234h:5678h
        aam
        db      0D4h,21h
        aad
        db      0D5h,10h
        int     03
        sgdt    [0000]
        push    small es
        push    large cs
        push    small ss
        push    large ds
        push    small fs
        push    large gs
        pop     small gs
        pop     large fs
        pop     small ds
        pop     large ss
        pop     small es
        retf    1234h
        retn    1234h
        int     21h
        pop     dword ptr ds:[bx]
        jmp     word ptr ds:[0000]
        push    word ptr ss:[edi]
        not     byte ptr ds:[0000]
        inc     bh
        idiv    ch
        call    fword ptr ds:[0000]
        jmp     dword ptr ds:[0000]
        setp    [0000]
        sldt    [0000]
        verr    [0000]
        inc     bp
        inc     esp
        dec     eax
        dec     si
        push    cx
        push    edi
        pop     dx
        pop     ebx
        bswap   eax
        bswap   sp
        push    small 1234h
        push    large 12345678h
        jo      $+8000h
        call    $+8000h
        jmp     $+8000h
        push    small -1
        push    large -3
        db      66h
        loopne  $-1
        loopde  $
        loop    $
        jecxz   $
        jmp     $
        je      $
        cbw
        cwde
        cwd
        cdq
        pusha
        pushad
        popad
        popa
        pushf
        pushfd
        popfd
        popf
        enter   0000h,00h
        enterd  0000h,00h
        db      66h
        enter   0000h,00h
        leaved
        leave
        iret
        iretd
        retn
        retf
        xlatb
        xlat    byte ptr gs:[bx]
        xlat    byte ptr ss:[ebx]
        db      0Fh,0C7h,38h
        rep ins byte ptr es:[di],dx
        rep ins word ptr es:[di],dx
        rep ins dword ptr es:[di],dx
        rep ins byte ptr es:[edi],dx
        rep ins word ptr es:[edi],dx
        rep ins dword ptr es:[edi],dx
        rep outs dx,byte ptr es:[si]
        rep outs dx,word ptr cs:[si]
        rep outs dx,dword ptr ss:[si]
        rep outs dx,byte ptr es:[esi]
        rep outs dx,word ptr cs:[esi]
        rep outs dx,dword ptr ss:[esi]
        rep movs byte ptr es:[di],byte ptr fs:[si]
        rep movs word ptr es:[di],word ptr gs:[si]
        rep movs dword ptr es:[di],dword ptr es:[si]
        rep movs byte ptr es:[edi],byte ptr fs:[esi]
        rep movs word ptr es:[edi],word ptr gs:[esi]
        rep movs dword ptr es:[edi],dword ptr es:[esi]
        rep cmps byte ptr es:[di],byte ptr es:[si]      ;tasm bug: must use
        rep cmps word ptr es:[di],word ptr es:[si]      ; es:si
        rep cmps dword ptr es:[di],dword ptr es:[si]
        rep cmps byte ptr es:[edi],byte ptr es:[esi]
        rep cmps word ptr es:[edi],word ptr es:[esi]
        rep cmps dword ptr es:[edi],dword ptr es:[esi]
        rep stos byte ptr es:[di]
        rep stos word ptr es:[di]
        rep stos dword ptr es:[di]
        rep stos byte ptr es:[edi]
        rep stos word ptr es:[edi]
        rep stos dword ptr es:[edi]
        rep lods byte ptr es:[si]
        rep lods word ptr cs:[si]
        rep lods dword ptr ss:[si]
        rep lods byte ptr es:[esi]
        rep lods word ptr cs:[esi]
        rep lods dword ptr ss:[esi]
        rep scas byte ptr es:[di]
        rep scas word ptr es:[di]
        rep scas dword ptr es:[di]
        rep scas byte ptr es:[edi]
        rep scas word ptr es:[edi]
        rep scas dword ptr es:[edi]
        imul    eax,[0000],12345678h
        imul    cx,dx,1234h
        imul    sp,[ebp],-3
        imul    bp,[bx],-5
        shld    [0000],esi,02h
        shrd    ax,dx,04h
        shld    [0000],esp,04h
        shrd    cx,bx,08h
        shld    edx,eax,cl
        shrd    [1234h],esp,cl
        db      80h,00h,90h
        db      82h,00h,90h
        test    cx,1234h
        not     sp
        db      0FFh,38h
ends    _text

        end     start
