📄 opcodes.asm
字号:
; /* Catch- all */
opcode <0f8h,0d8h,opn_esc,OP_ESC,2,0,0> ;ESC
opcode <0,0,0,0,0,0,0>
;
; now comes a table used only by the assembler for various aliased
; names
;
synonymTable label word
opcode <0ffh,0d7h,opn_xlatb,OP_CODEONLY,1,0,0> ;XLATB
opcode <0ffh,0e0h,opn_loopne,OP_SHORTBRANCH,2,0,0> ;LOOPNE
opcode <0ffh,0e1h,opn_loope,OP_SHORTBRANCH,2,0,0> ;LOOPE
opcode <0ffh,060h,opn_pushad,OP_OPSIZE1BYTE,1,1,0> ;PUSHAD
opcode <0ffh,061h,opn_popad,OP_OPSIZE1BYTE,1,1,0> ;POPAD
opcode <0ffh,09ch,opn_pushfd,OP_OPSIZE1BYTE,1,0,0> ;PUSHFD
opcode <0ffh,09dh,opn_popfd,OP_OPSIZE1BYTE,1,0,0> ;POPFD
opcode <0ffh,0a5h,opn_movsw,OP_CODEONLY,1,0,0> ;MOVSW
opcode <0ffh,0a7h,opn_cmpsw,OP_CODEONLY,1,0,0> ;CMPSW
opcode <0ffh,0abh,opn_stosw,OP_CODEONLY,1,0,0> ;STOSW
opcode <0ffh,0adh,opn_lodsw,OP_CODEONLY,1,0,0> ;LODSW
opcode <0ffh,0afh,opn_scasw,OP_CODEONLY,1,0,0> ;SCASW
opcode <0ffh,0a5h,opn_movsd,OP_OPSIZE1BYTE,1,0,0> ;MOVSD
opcode <0ffh,0a7h,opn_cmpsd,OP_OPSIZE1BYTE,1,0,0> ;CMPSD
opcode <0ffh,0abh,opn_stosd,OP_OPSIZE1BYTE,1,0,0> ;STOSD
opcode <0ffh,0adh,opn_lodsd,OP_OPSIZE1BYTE,1,0,0> ;LODSD
opcode <0ffh,0afh,opn_scasd,OP_OPSIZE1BYTE,1,0,0> ;SCASD
opcode <0ffh,06dh,opn_insw,OP_CODEONLY,1,1,0> ;INSW
opcode <0ffh,06dh,opn_insd,OP_OPSIZE1BYTE,1,1,0> ;INSD
opcode <0ffh,06fh,opn_outsw,OP_CODEONLY,1,1,0> ;OUTSW
opcode <0ffh,06fh,opn_outsd,OP_OPSIZE1BYTE,1,1,0> ;OUTSD
opcode <0ffh,072h,opn_jc,OP_SHORTBRANCH,2,0,0> ;JC
opcode <0ffh,082h,opn_jc,OP_BRANCH,2,3,0> ;JC
opcode <0ffh,072h,opn_jnae,OP_SHORTBRANCH,2,0,0> ;JNAE
opcode <0ffh,082h,opn_jnae,OP_BRANCH,2,3,0> ;JNAE
opcode <0ffh,073h,opn_jnc,OP_SHORTBRANCH,2,0,0> ;JNC
opcode <0ffh,083h,opn_jnc,OP_BRANCH,2,3,0> ;JNC
opcode <0ffh,073h,opn_jae,OP_SHORTBRANCH,2,0,0> ;JAE
opcode <0ffh,083h,opn_jae,OP_BRANCH,2,3,0> ;JAE
opcode <0ffh,074h,opn_je,OP_SHORTBRANCH,2,0,0> ;JE
opcode <0ffh,084h,opn_je,OP_BRANCH,2,3,0> ;JE
opcode <0ffh,075h,opn_jne,OP_SHORTBRANCH,2,0,0> ;JNE
opcode <0ffh,085h,opn_jne,OP_BRANCH,2,3,0> ;JNE
opcode <0ffh,076h,opn_jna,OP_SHORTBRANCH,2,0,0> ;JNA
opcode <0ffh,086h,opn_jna,OP_BRANCH,2,3,0> ;JNA
opcode <0ffh,077h,opn_jnbe,OP_SHORTBRANCH,2,0,0> ;JNBE
opcode <0ffh,087h,opn_jnbe,OP_BRANCH,2,3,0> ;JNBE
opcode <0ffh,07ah,opn_jpe,OP_SHORTBRANCH,2,0,0> ;JPE
opcode <0ffh,08ah,opn_jpe,OP_BRANCH,2,3,0> ;JPE
opcode <0ffh,07bh,opn_jpo,OP_SHORTBRANCH,2,0,0> ;JPO
opcode <0ffh,08bh,opn_jpo,OP_BRANCH,2,3,0> ;JPO
opcode <0ffh,07ch,opn_jnge,OP_SHORTBRANCH,2,0,0> ;JNGE
opcode <0ffh,08ch,opn_jnge,OP_BRANCH,2,3,0> ;JNGE
opcode <0ffh,07dh,opn_jnl,OP_SHORTBRANCH,2,0,0> ;JNL
opcode <0ffh,08dh,opn_jnl,OP_BRANCH,2,3,0> ;JNL
opcode <0ffh,07eh,opn_jng,OP_SHORTBRANCH,2,0,0> ;JNG
opcode <0ffh,08eh,opn_jng,OP_BRANCH,2,3,0> ;JNG
opcode <0ffh,07fh,opn_jnle,OP_SHORTBRANCH,2,0,0> ;JNLE
opcode <0ffh,08fh,opn_jnle,OP_BRANCH,2,3,0> ;JNLE
opcode <038ffh,092h,opn_setnae,OP_NOSTRICTRM ,2,3,0> ;SETNAE
opcode <038ffh,092h,opn_setc,OP_NOSTRICTRM ,2,3,0> ;SETC
opcode <038ffh,093h,opn_setnc,OP_NOSTRICTRM ,2,3,0> ;SETNC
opcode <038ffh,093h,opn_setae,OP_NOSTRICTRM ,2,3,0> ;SETAE
opcode <038ffh,094h,opn_sete,OP_NOSTRICTRM ,2,3,0> ;SETE
opcode <038ffh,095h,opn_setne,OP_NOSTRICTRM ,2,3,0> ;SETNE
opcode <038ffh,096h,opn_setna,OP_NOSTRICTRM ,2,3,0> ;SETNA
opcode <038ffh,097h,opn_setnbe,OP_NOSTRICTRM ,2,3,0> ;SETNBE
opcode <038ffh,09ah,opn_setpe,OP_NOSTRICTRM ,2,3,0> ;SETPE
opcode <038ffh,09bh,opn_setpo,OP_NOSTRICTRM ,2,3,0> ;SETPO
opcode <038ffh,09ch,opn_setnge,OP_NOSTRICTRM ,2,3,0> ;SETNGE
opcode <038ffh,09dh,opn_setnl,OP_NOSTRICTRM ,2,3,0> ;SETNL
opcode <038ffh,09eh,opn_setng,OP_NOSTRICTRM ,2,3,0> ;SETNG
opcode <038ffh,09fh,opn_setnle,OP_NOSTRICTRM ,2,3,0> ;SETNLE
opcode <0ffh,098h,opn_cwde,OP_OPSIZE1BYTE,1,0,0> ;CWDE
opcode <0ffh,099h,opn_cdq,OP_OPSIZE1BYTE,1,0,0> ;CDQ
opcode <0ffh,09bh,opn_fwait,OP_CODEONLY,1,0,0> ;FWAIT
opcode <0ffffh,00d1d8h,opn_fcom,OP_CODEONLY,2,0,0> ;FCOM
opcode <0ffffh,00d9d8h,opn_fcomp,OP_CODEONLY,2,0,0> ;FCOMP
opcode <0ffffh,00e1ddh,opn_fucom,OP_CODEONLY,2,0,0> ;FUCOM
opcode <0ffffh,00e9ddh,opn_fucomp,OP_CODEONLY,2,0,0> ;FUCOMP
opcode <0ffffh,00c9d9h,opn_fxch,OP_CODEONLY,2,0,0> ;FXCH
opcode <0,0,0,0,0,0,0>
indexes dw group000xxxxx, group001xxxxx, group010xxxxx, group011xxxxx
dw group100xxxxx, group101xxxxx, group110xxxxx, group111xxxxx
mnemonicMatchCount dw 0
mnemonicMatchAddrTable dw 16 DUP (0)
;
.CODE
;
; find an opcode. FS:SI points to the current byte of code, which is assumed
; to be the first byte of this opcode.
; Oops, actually SI points to the first byte of the opcode PAST any
; override bytes
;OUTPUT: AX contains the opcode, BX points to the opcode structure for it
; Apparently there is an option, which can be disabled, to permit
; disassembling instructions found on the 386 and above. So if we find
; an instruction and THEN find that this option is disabled, we
; decide that we didn't find the instruction after all.
; CY if not found
;
FindOpcode PROC
mov [x86pfx],0
mov bx,offset groupx386 ; Assume it is an 0F opcode
inc si ; Point to next byte
cmp BYTE PTR fs:[si-1],0fh ; Is it 0F?
jnz short not0ftable ; No, try another table
or [x86pfx],1 ; yes, flag as a prefix byte
jmp gotable
not0ftable:
mov [x86pfx],0 ; not the 0f prefix table
dec si ; Else point back to first byte
mov bx,offset floats ; Assume floating
movzx eax,byte ptr fs:[si] ; Get the opcode
and al,0f8h ; Apply the FLOAT mask
cmp al,0d8h ; Apply FLOAT compare
jz short gotable ; Yes, go look for opcode
shr al,5 ; get top 3 bits of opcode
mov bx,indexes[EAX*2] ; use as WORD table index
gotable:
test WORD PTR [bx],-1 ; See if at end of table
jz short noentry ; Yes, not found
mov ax,fs:[si] ; Get the opcode
and ax,[bx + OPCODE.MSK] ; Mask it
cmp ax,[bx + OPCODE.COMPARE]; Compare with the compare value
jz short gotentry ; Quit if found
add bx,OPCODESIZE ; Else go to next entry
jmp gotable ;
gotentry:
test [Disassemble32Bit],1 ;are 386+ instructions supported?
jnz okentry ;if so, we got it
test [bx + OPCODE.FLAGS],1 ;else report not found
jnz noentry
okentry:
clc ; Found, exit
ret
noentry:
stc ; Not found, exit
ret
FindOpcode ENDP
;
; scan a table for matches with this opcode
; INPUT:Well, let's see...
; SI appears to point to a mnemonic for an opcode, somewere in memory
; DI appears to point to the beginning of a table of opcode structures
; AX appears to contain the length of the mnemonic string at [si]
; BX appears to contain some index, but the syntax confuses me.
; for mnemonicMatchAddrTable, it is some even value which
; cannot exceed 1Eh or else mnemonicMatchAddrTable will
; overflow
; for opcode.flags, it is apparently an offset from the top
; of the data segment to the start of this opcode
; structure. It appears to hold BOTH OF THESE AT ONCE!
; HOW?
; My best guess is that BX comes in as 0
;PROCESSING:
; Compare the string pointed to by DS:SI with the mnemonic pointed
; to by the current opcode structure pointed to in ES:DI. Each time
; we get a string match, we store the address of the structure
; containing the pointer to the matching string in a table. No table
; of opcode structures better have more than 10h matches, since there
; is no check for this.
;
;OUTPUT: The mnemonicMatchAddrTable table contains some number of addresses
; of opcode structures, possibly 0. My best guess is that the number
; of validentries in this table is found in (BX-2) SHR 1
;
;
findMnemonicMatches PROC
test word ptr [di],-1 ; end of table?
jz nomorent
mov cx,ax ; get len passed in AX
push di ;save pointer to structure
mov di,[di+opcode.mnemonic] ; get mnemonic from structure
push si ;save pointer to found mnemonic
repe cmpsb ; scan for match
pop si ;restore pointers
pop di
jnz nomatch ; no match?
test [Disassemble32Bit],1 ; yes match, check for 386 match
jnz okentrymatch
test [di + OPCODE.FLAGS],1 ;see if 386+ instruction
jnz nomatch ; not allowing 386 opcodes
okentrymatch:
mov [bx+mnemonicMatchAddrTable],di ; match, put it in match tab
add bx,2
nomatch:
add di,OPCODESIZE ; next entry
jmp findMnemonicMatches
nomorent:
ret
findMnemonicMatches ENDP
;
; main opcode lookup outine
; INPUT: By implication at findMnemonicMatches, AX must contain the length of
; the string being parsed, and SI points to a mnemonic string.
; These registers must be preserved until at least after the last
; call to findMnemonicMatches.
; OUTPUT: mnemonicMatCount contains the number of valid matches
; mnemonicMatchAddrTable contains near pointers to the opcode
; structures where we actually found the matches to the names
;
LookupOpName PROC
sub bx,bx ;initial match count = 0
mov cx,8 ;look through 8 tables
mov di,offset indexes ; match the main tabs
lp:
push di ;save pointer to indexes
push cx ;save table count
mov di,[di] ;find next table
call findMnemonicMatches ;get match list
pop cx ;restore loop count
pop di ;and index pointer
add di,2 ;goto next table pointer
loop lp ;for all tables
mov di,offset floats ; match the float tab
call findMnemonicMatches ;and seach floats too
mov di,offset groupx386 ; match the x386 tab (0F prefix)
call findMnemonicMatches ;search that for matches
mov di,offset synonymTable ; match the assembly extras tab
call findMnemonicMatches ;search synonyms
shr bx,1 ;restore count of finds
mov [mnemonicMatchCount],bx ; and save count
jnz lox ;we found at least one match
stc ; no match, error
lox:
ret ; back to caller
LookupOpName ENDP
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -