; ---------------------------------------- ; - Monitor/Debugger voor 386-processors - ; - (C) Copyright 1995 by F13 Software - ; ---------------------------------------- ; --------- Disassembly Module ----------- ; ---------------------------------------- .386p assume cs:CODE,ds:DATA,es:DATA ; ---------------------------------------- ; --------- LINKER DEFINITIONS ----------- ; ---------------------------------------- public disone,genregs,segregs,dfadsiz,dfopsiz extrn bin2hex : proc ; ---------------------------------------- ; ------------ DATA SECTION -------------- ; ---------------------------------------- DATA segment public use16 ; --------- OPCODE DEFINITIONS ----------- ; general form: db flags,'name',0,operand 1,operand 2,'name suffix',0,0ff ; ; note: in name strings, '^' means replace with 'e' if operand size==32 ; else don't print; ; '*' means replace with 'd' if operand size==32 ; else don't print; ; '&' means replace with 'd' if operand size==32 ; else replace with 'w'; ; '%' means replace with 'e' if address size==32 ; else don't print (only with j%cxz). ; ; flags byte format: bit 7 = with suffix ; bits 6-4 = opcode type ; bits 3-0 = operand count ; ; opcode type: 0 = normal opcode ; 1 = prefix ; 2 = operand size override ; 3 = address size override ; 4 = escape to 2-byte opcode set ; ; ----------- 1-byte opcodes ------------- opcode1 db 002h,'add ',0,000h,030h,0ffh db 002h,'add ',0,003h,033h,0ffh db 002h,'add ',0,030h,000h,0ffh db 002h,'add ',0,033h,003h,0ffh db 001h,'add al,',0,080h,0ffh db 001h,'add ^ax,',0,083h,0ffh db 000h,'push es',0,0ffh db 000h,'pop es',0,0ffh db 002h,'or ',0,000h,030h,0ffh db 002h,'or ',0,003h,033h,0ffh db 002h,'or ',0,030h,000h,0ffh db 002h,'or ',0,033h,003h,0ffh db 001h,'or al,',0,080h,0ffh db 001h,'or ^ax,',0,083h,0ffh db 000h,'push cs',0,0ffh db 040h,0ffh ; 2-byte escape code db 002h,'adc ',0,000h,030h,0ffh db 002h,'adc ',0,003h,033h,0ffh db 002h,'adc ',0,030h,000h,0ffh db 002h,'adc ',0,033h,003h,0ffh db 001h,'adc al,',0,080h,0ffh db 001h,'adc ^ax,',0,083h,0ffh db 000h,'push ss',0,0ffh db 000h,'pop ss',0,0ffh db 002h,'sbb ',0,000h,030h,0ffh db 002h,'sbb ',0,003h,033h,0ffh db 002h,'sbb ',0,030h,000h,0ffh db 002h,'sbb ',0,033h,003h,0ffh db 001h,'sbb al,',0,080h,0ffh db 001h,'sbb ^ax,',0,083h,0ffh db 000h,'push ds',0,0ffh db 000h,'pop ds',0,0ffh db 002h,'and ',0,000h,030h,0ffh db 002h,'and ',0,003h,033h,0ffh db 002h,'and ',0,030h,000h,0ffh db 002h,'and ',0,033h,003h,0ffh db 001h,'and al,',0,080h,0ffh db 001h,'and ^ax,',0,083h,0ffh db 010h,'es:',0,0ffh db 000h,'daa',0,0ffh db 002h,'sub ',0,000h,030h,0ffh db 002h,'sub ',0,003h,033h,0ffh db 002h,'sub ',0,030h,000h,0ffh db 002h,'sub ',0,033h,003h,0ffh db 001h,'sub al,',0,080h,0ffh db 001h,'sub ^ax,',0,083h,0ffh db 010h,'cs:',0,0ffh db 000h,'das',0,0ffh db 002h,'xor ',0,000h,030h,0ffh db 002h,'xor ',0,003h,033h,0ffh db 002h,'xor ',0,030h,000h,0ffh db 002h,'xor ',0,033h,003h,0ffh db 001h,'xor al,',0,080h,0ffh db 001h,'xor ^ax,',0,083h,0ffh db 010h,'ss:',0,0ffh db 000h,'aaa',0,0ffh db 002h,'cmp ',0,000h,030h,0ffh db 002h,'cmp ',0,003h,033h,0ffh db 002h,'cmp ',0,030h,000h,0ffh db 002h,'cmp ',0,033h,003h,0ffh db 001h,'cmp al,',0,080h,0ffh db 001h,'cmp ^ax,',0,083h,0ffh db 010h,'ds:',0,0ffh db 000h,'aas',0,0ffh db 000h,'inc ^ax',0,0ffh db 000h,'inc ^cx',0,0ffh db 000h,'inc ^dx',0,0ffh db 000h,'inc ^bx',0,0ffh db 000h,'inc ^sp',0,0ffh db 000h,'inc ^bp',0,0ffh db 000h,'inc ^si',0,0ffh db 000h,'inc ^di',0,0ffh db 000h,'dec ^ax',0,0ffh db 000h,'dec ^cx',0,0ffh db 000h,'dec ^dx',0,0ffh db 000h,'dec ^bx',0,0ffh db 000h,'dec ^sp',0,0ffh db 000h,'dec ^bp',0,0ffh db 000h,'dec ^si',0,0ffh db 000h,'dec ^di',0,0ffh db 000h,'push ^ax',0,0ffh db 000h,'push ^cx',0,0ffh db 000h,'push ^dx',0,0ffh db 000h,'push ^bx',0,0ffh db 000h,'push ^sp',0,0ffh db 000h,'push ^bp',0,0ffh db 000h,'push ^si',0,0ffh db 000h,'push ^di',0,0ffh db 000h,'pop ^ax',0,0ffh db 000h,'pop ^cx',0,0ffh db 000h,'pop ^dx',0,0ffh db 000h,'pop ^bx',0,0ffh db 000h,'pop ^sp',0,0ffh db 000h,'pop ^bp',0,0ffh db 000h,'pop ^si',0,0ffh db 000h,'pop ^di',0,0ffh db 000h,'pusha*',0,0ffh db 000h,'popa*',0,0ffh db 002h,'bound ',0,033h,023h,0ffh db 002h,'arpl ',0,001h,031h,0ffh db 010h,'fs:',0,0ffh db 010h,'gs:',0,0ffh db 020h,0ffh ; Operand size override db 030h,0ffh ; Address size override db 001h,'push ',0,083h,0ffh db 003h,'imul ',0,033h,003h,083h,0ffh db 001h,'push ',0,080h,0ffh db 003h,'imul ',0,033h,003h,080h,0ffh db 000h,'insb',0,0ffh db 000h,'ins&',0,0ffh db 000h,'outsb',0,0ffh db 000h,'outs&',0,0ffh db 001h,'jo short ',0,086h,0ffh db 001h,'jno short ',0,086h,0ffh db 001h,'jb short ',0,086h,0ffh db 001h,'jnb short ',0,086h,0ffh db 001h,'jz short ',0,086h,0ffh db 001h,'jnz short ',0,086h,0ffh db 001h,'jbe short ',0,086h,0ffh db 001h,'jnbe short ',0,086h,0ffh db 001h,'js short ',0,086h,0ffh db 001h,'jns short ',0,086h,0ffh db 001h,'jp short ',0,086h,0ffh db 001h,'jnp short ',0,086h,0ffh db 001h,'jl short ',0,086h,0ffh db 001h,'jnl short ',0,086h,0ffh db 001h,'jle short ',0,086h,0ffh db 001h,'jnle short ',0,086h,0ffh db 003h,0,090h,000h,080h,0ffh db 003h,0,090h,003h,083h,0ffh db 003h,0,090h,000h,080h,0ffh db 003h,0,090h,003h,088h,0ffh db 002h,'test ',0,000h,030h,0ffh db 002h,'test ',0,003h,033h,0ffh db 002h,'xchg ',0,000h,030h,0ffh db 002h,'xchg ',0,003h,033h,0ffh db 002h,'mov ',0,000h,030h,0ffh db 002h,'mov ',0,003h,033h,0ffh db 002h,'mov ',0,030h,000h,0ffh db 002h,'mov ',0,033h,003h,0ffh db 002h,'mov ',0,001h,041h,0ffh db 002h,'lea ',0,033h,020h,0ffh db 002h,'mov ',0,041h,001h,0ffh db 001h,'pop ',0,003h,0ffh db 000h,'nop',0,0ffh db 000h,'xchg ^ax,^cx',0,0ffh db 000h,'xchg ^ax,^dx',0,0ffh db 000h,'xchg ^ax,^bx',0,0ffh db 000h,'xchg ^ax,^sp',0,0ffh db 000h,'xchg ^ax,^bp',0,0ffh db 000h,'xchg ^ax,^si',0,0ffh db 000h,'xchg ^ax,^di',0,0ffh db 000h,'cbw',0,0ffh db 000h,'cwd',0,0ffh db 001h,'call ',0,085h,0ffh db 000h,'wait',0,0ffh db 000h,'pushf',0,0ffh db 000h,'popf',0,0ffh db 000h,'sahf',0,0ffh db 000h,'lahf',0,0ffh db 081h,'mov al,[',0,084h,']',0,0ffh db 081h,'mov ^ax,[',0,084h,']',0,0ffh db 081h,'mov [',0,084h,'],al',0,0ffh db 081h,'mov [',0,084h,'],^ax',0,0ffh db 000h,'movsb',0,0ffh db 000h,'movs&',0,0ffh db 000h,'cmpsb',0,0ffh db 000h,'cmps&',0,0ffh db 001h,'test al,',0,080h,0ffh db 001h,'test ^ax,',0,083h,0ffh db 000h,'stosb',0,0ffh db 000h,'stos&',0,0ffh db 000h,'lodsb',0,0ffh db 000h,'lods&',0,0ffh db 000h,'scasb',0,0ffh db 000h,'scas&',0,0ffh db 001h,'mov al,',0,080h,0ffh db 001h,'mov cl,',0,080h,0ffh db 001h,'mov dl,',0,080h,0ffh db 001h,'mov bl,',0,080h,0ffh db 001h,'mov ah,',0,080h,0ffh db 001h,'mov ch,',0,080h,0ffh db 001h,'mov dh,',0,080h,0ffh db 001h,'mov bh,',0,080h,0ffh db 001h,'mov ^ax,',0,083h,0ffh db 001h,'mov ^cx,',0,083h,0ffh db 001h,'mov ^dx,',0,083h,0ffh db 001h,'mov ^bx,',0,083h,0ffh db 001h,'mov ^sp,',0,083h,0ffh db 001h,'mov ^bp,',0,083h,0ffh db 001h,'mov ^si,',0,083h,0ffh db 001h,'mov ^di,',0,083h,0ffh db 003h,0,091h,000h,080h,0ffh db 003h,0,091h,003h,080h,0ffh db 001h,'retn ',0,081h,0ffh db 000h,'retn',0,0ffh db 002h,'les ',0,033h,024h,0ffh db 002h,'lds ',0,033h,024h,0ffh db 002h,'mov ',0,000h,080h,0ffh db 002h,'mov ',0,003h,083h,0ffh db 002h,'enter ',0,081h,080h,0ffh db 000h,'leave',0,0ffh db 001h,'retf ',0,081h,0ffh db 000h,'retf',0,0ffh db 000h,'int 3',0,0ffh db 001h,'int ',0,080h,0ffh db 000h,'into',0,0ffh db 000h,'iret',0,0ffh db 082h,0,091h,000h,',1',0,0ffh db 082h,0,091h,003h,',1',0,0ffh db 082h,0,091h,000h,',cl',0,0ffh db 082h,0,091h,003h,',cl',0,0ffh db 001h,'aam ',0,080h,0ffh db 001h,'aad ',0,080h,0ffh db 0ffh db 000h,'xlat',0,0ffh db 001h,'esc 0,',0,000h,0ffh db 001h,'esc 1,',0,000h,0ffh db 001h,'esc 2,',0,000h,0ffh db 001h,'esc 3,',0,000h,0ffh db 001h,'esc 4,',0,000h,0ffh db 001h,'esc 5,',0,000h,0ffh db 001h,'esc 6,',0,000h,0ffh db 001h,'esc 7,',0,000h,0ffh db 001h,'loopne ',0,086h,0ffh db 001h,'loope ',0,086h,0ffh db 001h,'loop ',0,086h,0ffh db 001h,'j%cxz ',0,086h,0ffh db 001h,'in al,',0,080h,0ffh db 001h,'in ^ax,',0,080h,0ffh db 081h,'out ',0,080h,',al',0,0ffh db 081h,'out ',0,080h,',^ax',0,0ffh db 001h,'call near ',0,087h,0ffh db 001h,'jmp near ',0,087h,0ffh db 001h,'jmp far ',0,085h,0ffh db 001h,'jmp short ',0,086h,0ffh db 000h,'in al,dx',0,0ffh db 000h,'in ^ax,dx',0,0ffh db 000h,'out dx,al',0,0ffh db 000h,'out dx,^ax',0,0ffh db 010h,'lock',0,0ffh db 0ffh db 010h,'repne',0,0ffh db 010h,'rep',0,0ffh db 000h,'hlt',0,0ffh db 000h,'cmc',0,0ffh db 001h,0,092h,0ffh db 001h,0,093h,0ffh db 000h,'clc',0,0ffh db 000h,'stc',0,0ffh db 000h,'cli',0,0ffh db 000h,'sti',0,0ffh db 000h,'cld',0,0ffh db 000h,'std',0,0ffh db 002h,0,094h,000h,0ffh db 001h,0,095h,0ffh ; ----------- 2-byte opcodes ------------- opcode2 db 002h,0,096h,001h,0ffh db 001h,0,097h,0ffh db 002h,'lar ',0,033h,001h,0ffh db 002h,'lsl ',0,033h,001h,0ffh db 2 dup (0ffh) db 000h,'clts',0,0ffh db 19h dup (0ffh) db 002h,'mov ',0,012h,052h,0ffh db 002h,'mov ',0,012h,062h,0ffh db 002h,'mov ',0,052h,012h,0ffh db 002h,'mov ',0,062h,012h,0ffh db 002h,'mov ',0,012h,072h,0ffh db 0ffh db 002h,'mov ',0,072h,012h,0ffh db 59h dup (0ffh) db 001h,'jo near ',0,087h,0ffh db 001h,'jno near ',0,087h,0ffh db 001h,'jb near ',0,087h,0ffh db 001h,'jnb near ',0,087h,0ffh db 001h,'jz near ',0,087h,0ffh db 001h,'jnz near ',0,087h,0ffh db 001h,'jbe near ',0,087h,0ffh db 001h,'jnbe near ',0,087h,0ffh db 001h,'js near ',0,087h,0ffh db 001h,'jns near ',0,087h,0ffh db 001h,'jp near ',0,087h,0ffh db 001h,'jnp near ',0,087h,0ffh db 001h,'jl near ',0,087h,0ffh db 001h,'jnl near ',0,087h,0ffh db 001h,'jle near ',0,087h,0ffh db 001h,'jnle near ',0,087h,0ffh db 001h,'seto ',0,000h,0ffh db 001h,'setno ',0,000h,0ffh db 001h,'setb ',0,000h,0ffh db 001h,'setnb ',0,000h,0ffh db 001h,'setz ',0,000h,0ffh db 001h,'setnz ',0,000h,0ffh db 001h,'setbe ',0,000h,0ffh db 001h,'setnbe ',0,000h,0ffh db 001h,'sets ',0,000h,0ffh db 001h,'setns ',0,000h,0ffh db 001h,'setp ',0,000h,0ffh db 001h,'setnp ',0,000h,0ffh db 001h,'setl ',0,000h,0ffh db 001h,'setnl ',0,000h,0ffh db 001h,'setle ',0,000h,0ffh db 001h,'setnle ',0,000h,0ffh db 000h,'push fs',0,0ffh db 000h,'pop fs',0,0ffh db 0ffh db 002h,'bt ',0,003h,033h,0ffh db 003h,'shld ',0,003h,033h,080h,0ffh db 00ah,'shld ',0,003h,034h,',cl',0,0ffh db 2 dup (0ffh) db 000h,'push gs',0,0ffh db 000h,'pop gs',0,0ffh db 0ffh db 002h,'bts ',0,003h,033h,0ffh db 003h,'shrd ',0,003h,033h,080h,0ffh db 00ah,'shrd ',0,003h,034h,',cl',0,0ffh db 0ffh db 002h,'imul ',0,033h,003h,0ffh db 2 dup (0ffh) db 002h,'lss ',0,033h,023h,0ffh db 002h,'btr ',0,003h,033h,0ffh db 002h,'lfs ',0,033h,023h,0ffh db 002h,'lgs ',0,033h,023h,0ffh db 002h,'movzx ',0,033h,000h,0ffh db 002h,'movzx ',0,033h,001h,0ffh db 2 dup (0ffh) db 003h,0,098h,003h,080h,0ffh db 002h,'btc ',0,003h,033h,0ffh db 002h,'bsf ',0,033h,003h,0ffh db 002h,'bsr ',0,033h,003h,0ffh db 002h,'movsx ',0,033h,000h,0ffh db 002h,'movsx ',0,033h,001h,0ffh db 64 dup (0ffh) ; ---------- Group definitons ------------ groups db 000h,'add ',0,0ffh db 000h,'or ',0,0ffh db 000h,'adc ',0,0ffh db 000h,'sbb ',0,0ffh db 000h,'and ',0,0ffh db 000h,'sub ',0,0ffh db 000h,'xor ',0,0ffh db 000h,'cmp ',0,0ffh ; Group 1 db 000h,'rol ',0,0ffh db 000h,'ror ',0,0ffh db 000h,'rcl ',0,0ffh db 000h,'rcr ',0,0ffh db 000h,'shl ',0,0ffh db 000h,'shr ',0,0ffh db 000h,'shl ',0,0ffh db 000h,'sar ',0,0ffh ; Group 2 db 002h,'test ',0,000h,080h,0ffh db 0ffh db 001h,'not ',0,000h,0ffh db 001h,'neg ',0,000h,0ffh db 001h,'mul al,',0,000h,0ffh db 001h,'imul al,',0,000h,0ffh db 001h,'div al,',0,000h,0ffh db 001h,'idiv al,',0,000h,0ffh ; Group 3-1 db 002h,'test ',0,003h,083h,0ffh db 0ffh db 001h,'not ',0,003h,0ffh db 001h,'neg ',0,003h,0ffh db 001h,'mul ^ax,',0,003h,0ffh db 001h,'imul ^ax,',0,003h,0ffh db 001h,'div ^ax,',0,003h,0ffh db 001h,'idiv ^ax,',0,003h,0ffh ; Group 3-2 db 000h,'inc ',0,0ffh db 000h,'dec ',0,0ffh db 6 dup (0ffh) ; Group 4 db 001h,'inc ',0,003h,0ffh db 001h,'dec ',0,003h,0ffh db 001h,'call near ',0,003h,0ffh db 001h,'call far ',0,005h,0ffh db 001h,'jmp near ',0,003h,0ffh db 001h,'jmp far ',0,005h,0ffh db 001h,'push ',0,003h,0ffh db 0ffh ; Group 5 db 000h,'sldt ',0,0ffh db 000h,'str ',0,0ffh db 000h,'lldt ',0,0ffh db 000h,'ltr ',0,0ffh db 000h,'verr ',0,0ffh db 000h,'verw ',0,0ffh db 2 dup (0ffh) ; Group 6 db 001h,'sgdt ',0,022h,0ffh db 001h,'sidt ',0,022h,0ffh db 001h,'lgdt ',0,022h,0ffh db 001h,'lidt ',0,022h,0ffh db 001h,'smsw ',0,001h,0ffh db 0ffh db 001h,'lmsw ',0,001h,0ffh db 0ffh ; Group 7 db 4 dup (0ffh) db 000h,'bt ',0,0ffh db 000h,'bts ',0,0ffh db 000h,'btr ',0,0ffh db 000h,'btc ',0,0ffh ; Group 8 ; ----------- modR/M tables -------------- genregs db 'al',0,0,'ax',0,0,'eax',0 db 'cl',0,0,'cx',0,0,'ecx',0 db 'dl',0,0,'dx',0,0,'edx',0 db 'bl',0,0,'bx',0,0,'ebx',0 db 'ah',0,0,'sp',0,0,'esp',0 db 'ch',0,0,'bp',0,0,'ebp',0 db 'dh',0,0,'si',0,0,'esi',0 db 'bh',0,0,'di',0,0,'edi',0 segregs db 'ecsdfg' marr16 db '[bx+si]',0,0ffh ; no disps db '[bx+di]',0,0ffh db '[bp+si]',0,0ffh db '[bp+di]',0,0ffh db '[si]',0,0ffh db '[di]',0,0ffh db '[',0,001h,']',0,0ffh ; disp16 db '[bx]',0,0ffh db '[bx+si',0,008h,']',0,0ffh ; disp8 db '[bx+di',0,008h,']',0,0ffh db '[bp+si',0,008h,']',0,0ffh db '[bp+di',0,008h,']',0,0ffh db '[si',0,008h,']',0,0ffh db '[di',0,008h,']',0,0ffh db '[bp',0,008h,']',0,0ffh db '[bx',0,008h,']',0,0ffh db '[bx+si+',0,001h,']',0,0ffh ; disp16 db '[bx+di+',0,001h,']',0,0ffh db '[bp+si+',0,001h,']',0,0ffh db '[bp+di+',0,001h,']',0,0ffh db '[si+',0,001h,']',0,0ffh db '[di+',0,001h,']',0,0ffh db '[bp+',0,001h,']',0,0ffh db '[bx+',0,001h,']',0,0ffh marr32 db '[eax]',0,0ffh ; no disps db '[ecx]',0,0ffh db '[edx]',0,0ffh db '[ebx]',0,0ffh db '[',0,00fh,']',0,0ffh ; SIB db '[',0,002h,']',0,0ffh ; disp32 db '[esi]',0,0ffh db '[edi]',0,0ffh db '[eax',0,008h,']',0,0ffh ; disp8 db '[ecx',0,008h,']',0,0ffh db '[edx',0,008h,']',0,0ffh db '[ebx',0,008h,']',0,0ffh db '[',0,008h,'+',0,00fh,']',0,0ffh ; disp8+SIB db '[ebp',0,008h,']',0,0ffh db '[esi',0,008h,']',0,0ffh db '[edi',0,008h,']',0,0ffh db '[eax+',0,002h,']',0,0ffh ; disp32 db '[ecx+',0,002h,']',0,0ffh db '[edx+',0,002h,']',0,0ffh db '[ebx+',0,002h,']',0,0ffh db '[',0,002h,'+',0,00fh,']',0,0ffh ; disp32+SIB db '[ebp+',0,002h,']',0,0ffh db '[esi+',0,002h,']',0,0ffh db '[edi+',0,002h,']',0,0ffh ; --------------- Rest ------------------- dfadsiz db 0 dfopsiz db 0 tpadsiz db 0 tpopsiz db 0 modrmrd db 0 modrm db 0 lastgrp db 0 DATA ends ; ---------------------------------------- ; ------------ CODE SECTION -------------- ; ---------------------------------------- CODE segment public use16 searchn proc near ; DS:SI=array; CX=search count sn1: cmp byte ptr [si],0ffh lahf inc si sahf jnz sn1 loop sn1 sn0: ret endp copystr proc near push ax cs0: lodsb test al,al jz short cs1 cmp al,'^' jnz short cs2 cmp byte ptr tpopsiz,1 jnz cs0 mov al,'e' jmp short cs5 cs2: cmp al,'*' jnz short cs3 cmp byte ptr tpopsiz,1 jnz cs0 mov al,'d' jmp short cs5 cs3: cmp al,'&' jnz short cs4 mov al,'w' cmp byte ptr tpopsiz,1 jnz short cs5 mov al,'d' jmp short cs5 cs4: cmp al,'%' jnz short cs5 cmp byte ptr tpadsiz,1 jnz short cs0 mov al,'e' cs5: stosb jmp short cs0 cs1: pop ax ret endp dosib proc near ; BL=modrm byte push si mov dl,bl mov al,fs:[bp] inc bp push ax mov bl,al and bx,7 ; BX=base cmp bl,5 ; Base=EBP/immediate? jnz short ds0 inc bl test dl,0c0h jnz short ds0 mov cl,2 call doimmed jmp short ds1 ds0: imul bx,12 lea si,[bx+offset genregs+8] ; SI=base register name call copystr ds1: pop ax xor ah,ah shl ax,2 shr al,5 ; AH=scale, AL=index cmp al,4 jz short ds2 ; Helemaal geen index push ax mov bl,al mov al,'+' stosb xor bh,bh imul bx,12 lea si,[bx+offset genregs+8] call copystr ; SI=index register name pop cx ; CH=scale factor test ch,ch jz ds2 ; Geen scale factor mov cl,ch mov ax,12ah ; AL='*', AH=1 shl ah,cl add ah,'0' stosw ds2: pop si ret endp dogroup proc near ; BL=modrm, AL=group mov si,offset groups mov cl,al xor ch,ch shl cx,3 shr bl,3 and bx,7 add cx,bx jz short dg0 call searchn dg0: lodsb cmp al,0ffh jz short dg1 call normop ret dg1: call illegal ret endp domodrm proc near ; AL=type/group, AH=what to do mov bl,modrm push si cmp ah,9 jnz short dm7 call dogroup mov byte ptr lastgrp,1 jmp near ptr dm3 dm7: cmp al,3 jnz short dm0 mov al,tpopsiz inc al dm0: mov cl,3 cmp ah,2 ja short dm2 ; Als type>2, sowieso register in reg mov cl,bl and cl,0c0h cmp cl,0c0h jnz short dm1 ; Als mod!=11 dan memory xor cl,cl ; Anders als niet memory, register in r/m dm2: shr bl,cl and bx,7 ; BX=register no cmp ah,3 ja short dm9 ; General register? imul bx,12 shl al,2 ; AL=type (0,2,4=b,w,d) cbw add bx,ax lea si,[bx+offset genregs] call copystr jmp short dm3 dm9: cmp ah,4 jnz short dm10 ; Segment register? mov al,bl mov bx,offset segregs xlat stosb mov al,'s' stosb jmp short dm3 dm10: cmp ah,5 jnz short dm11 ; Control register? (cr0..cr3) mov ax,'rc' jmp short dm13 dm11: cmp ah,6 jnz short dm12 ; Debug register? (dr0..dr3,dr6,dr7) mov ax,'rd' jmp short dm13 dm12: mov ax,'rt' ; Test register (tr6,tr7) dm13: stosw mov al,bl add al,'0' stosb jmp short dm3 dm1: and bl,7 shr cl,3 or cl,bl ; CL=amode idx mov si,offset marr16 cmp byte ptr tpadsiz,1 jnz short dm4 mov si,offset marr32 dm4: xor ch,ch jcxz dm5 call searchn ; Zoek amode entry in juiste tabel dm5: call copystr lodsb ; Codes: 0ffh=klaar, 00fh=SIB, rest=imm. type cmp al,0ffh jz short dm3 cmp al,00fh jnz short dm6 call dosib jmp short dm5 dm6: mov cl,al call near ptr doimmed jmp short dm5 dm3: pop si ret endp doimmed proc near ; CL=type mov eax,fs:[bp] mov dx,1 cmp cl,2 ja short di0 shl dl,cl jmp short di5 di0: cmp cl,3 jnz short di1 mov cl,tpopsiz inc cl shl dl,cl jmp short di5 di1: cmp cl,4 jnz short di2 mov cl,tpadsiz inc cl shl dl,cl jmp short di5 di2: cmp cl,5 jnz short di3 push ax mov cl,tpopsiz inc cl mov bx,1 shl bx,cl add bp,bx mov ax,fs:[bp] mov dx,2 add bp,dx push bx call bin2hex pop dx mov al,':' stosb pop ax jmp short di6 di3: cmp cl,6 jnz short di4 cbw add ax,bp inc ax mov dx,2 inc bp jmp short di6 di4: cmp cl,7 jnz short di7 mov cl,tpopsiz inc cl shl dl,cl add bp,dx movzx ebx,bp add eax,ebx jmp short di6 di7: inc bp mov dx,201h jmp short di6 ; Sign extended byte (incl. '+' or '-', leading zero and 'h') di5: add bp,dx di6: call bin2hex ret endp normop proc near ; AL=first byte in opcode array call copystr mov cl,al and cx,0fh jcxz short no2 push ax no0: mov byte ptr lastgrp,0 push cx lodsb xor ah,ah shl ax,4 shr al,4 ; AL=type, AH=amode push ax cmp ah,8 jz short no3 cmp byte ptr modrmrd,1 jz short no4 mov bl,fs:[bp] mov modrm,bl inc bp mov byte ptr modrmrd,1 no4: push bx call domodrm pop bx jmp short no5 no3: push bx mov cl,al call doimmed pop bx no5: pop ax pop cx cmp cx,1 jz short no6 cmp byte ptr lastgrp,1 jz short no6 mov al,',' stosb no6: loop no0 pop ax no2: test al,80h jz short no1 call copystr no1: ret endp prefix proc near call copystr mov al,' ' stosb mov si,offset opcode1 call decode ret endp oprsize proc near mov al,dfopsiz xor al,1 mov tpopsiz,al mov si,offset opcode1 call decode ret endp adrsize proc near mov al,dfadsiz xor al,1 mov tpadsiz,al mov si,offset opcode1 call decode ret endp escape proc near mov si,offset opcode2 call decode ret endp illegal proc near mov al,'?' stosb stosb stosb ret endp decode proc near ; FS:BP=source; ES:DI=buffer; DS:SI=opcode array mov byte ptr modrmrd,0 ; No modR/M yet movzx cx,fs:[bp] inc bp jcxz short dc0 call searchn dc0: lodsb mov bl,al shr bl,3 and bx,0eh cmp bx,4 shl 1 jbe short dc1 mov bx,5 shl 1 dc1: call word ptr cs:[bx+offset opcctbl] ret endp disone proc near ; FS:BP=source; ES:DI=buffer mov ax,fs mov dx,102h call bin2hex mov al,':' stosb mov ax,bp mov dx,102h call bin2hex push di mov al,' ' mov cx,29+13 rep stosb push bp mov si,offset opcode1 mov al,dfadsiz mov tpadsiz,al mov al,dfopsiz mov tpopsiz,al call decode xor al,al stosb pop si mov cx,bp sub cx,si mov bl,' ' cmp cx,14 jbe do1 mov cx,14 mov bl,'+' ; BL=char to add after code bytes do1: pop di inc di inc di mov dx,101h push cx ; Save instruction length push bx do0: push cx lods byte ptr fs:[si] call bin2hex mov al,' ' stosb pop cx loop do0 pop bx mov es:[di-1],bl pop ax ; Return instruction length ret endp opcctbl dw normop,prefix,oprsize,adrsize,escape,illegal CODE ends end