📄 mmx.asi
字号:
;;;; MMX.ASI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Agner Fog 2000 ;;;;
;; ;;
;; DEFINITION OF MMX INSTRUCTIONS ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.XLIST ;;
;; ;;
;; Instructions: ;;
;; To use MMX instructions with an assembler that doesn't support these, ;;
;; insert the following directive in your assembly file: ;;
;; INCLUDE MMX.ASI ;;
;; ;;
;; This file is written in MASM 5.10 syntax and works with TASM version 3.0 ;;
;; or higher and MASM version 5.10 or higher. ;;
;; The following assemblers may cause problems: ;;
;; MASM v. 5.10 has a bug that gives wrong jump addresses in 32 bit mode. ;;
;; TASM32 v. 4.0, 5.0, 5.0o, 5.0r have various bugs that make them crash ;;
;; in DOS or Windows or both when executing these macros. ;;
;; Microsoft ML version 6.11 doesn't work with these macros when output ;;
;; is in COFF format with certain linkers. ;;
;; ;;
;; The macros work in both 16 bit mode and 32 bit mode, provided that no ;;
;; prefixes are needed. Make sure that all memory operands can be addressed ;;
;; with the default segment register to avoid segment prefixes. Any ;;
;; prefixes needed must be hard-coded with the DB directive. ;;
;; ;;
;; Microprocessor specified must be .386 or higher. ;;
;; ;;
;; Note that operands containing space must be enclosed in angle brackets ;;
;; in order to be interpreted as single operands by the macros, example: ;;
;; MOVQ MM1, <QWORD PTR [ESI + 8]> ;;
;; or rewrite the operand to avoid the spaces: ;;
;; MOVQ MM1, [ESI+8] ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IFDEF @version ; Microsoft assembler
IF @version GE 612
; Assembler allready supports MMX instructions. Disable rest of file
.mmx
MMXSUPPORTED EQU 1
ELSE
IF @version GE 600
OPTION M510 ; Make compatible with MASM 5.10 syntax
ENDIF
ENDIF
ENDIF
IFNDEF MMXSUPPORTED
; macro used internally for examining whether parameters are mmx registers.
; mmx register names are replaced by corresponding general registers
; (returned in PAR1, PAR2)
MREGS MACRO R1, R2
LOCAL I
PAR1 EQU <R1>
PAR1M = 0
IRP M, <0,1,2,3,4,5,6,7>
IFIDNI <MM&&M>, <R1>
I = M
IRP F, <ax,cx,dx,bx,sp,bp,si,di>
IF I EQ 0
IF @WordSize GT 2
PAR1 EQU <e&&&F>
ELSE
PAR1 EQU <F>
ENDIF
PAR1M = 1
EXITM
ENDIF
I = I - 1
ENDM
EXITM
ENDIF
ENDM
PAR2 EQU <R2>
PAR2M = 0
IRP M, <0,1,2,3,4,5,6,7>
IFIDNI <MM&&M>, <R2>
I = M
IRP F, <ax,cx,dx,bx,sp,bp,si,di>
IF I EQ 0
IF @WordSize GT 2
PAR2 EQU <e&&&F>
ELSE
PAR2 EQU <F>
ENDIF
PAR2M = 1
EXITM
ENDIF
I = I - 1
ENDM
EXITM
ENDIF
ENDM
ENDM
; meta-macro for defining MMX instruction macro
MMXDEF MACRO OPNAME, OPCODE
OPNAME MACRO DST, SRC
LOCAL X, Y
&MREGS <DST>, <SRC>
X:
IF PAR2M
BSF PAR1, PAR2
ELSE
BSF PAR1, @WordSize PTR (PAR2)
ENDIF
Y:
ORG X+1
DB OPCODE
ORG Y
ENDM
ENDM
; meta-macro for defining MMX shift instruction macro
MMSHIFTDEF MACRO OPNAME, OPCODE, OPCODEI, REGI
OPNAME MACRO DST, SRC
LOCAL X, Y
&MREGS <DST>, <SRC>
X:
IF (.TYPE PAR2) AND 4 ; if immediate constant
IF @WordSize GT 2
BSF E&®I, PAR1
ELSE
BSF REGI, PAR1
ENDIF
DB SRC
Y:
ORG X+1
DB OPCODEI
ELSE
IF PAR2M
BSF PAR1, PAR2
ELSE
BSF PAR1, @WordSize PTR (PAR2)
ENDIF
Y:
ORG X+1
DB OPCODE
ENDIF
ORG Y
ENDM
ENDM
; define most mmx instructions
MMXDEF packssdw, 06BH
MMXDEF packsswb, 063H
MMXDEF packuswb, 067H
MMXDEF paddb, 0FCH
MMXDEF paddd, 0FEH
MMXDEF paddsb, 0ECH
MMXDEF paddsw, 0EDH
MMXDEF paddusb, 0DCH
MMXDEF paddusw, 0DDH
MMXDEF paddw, 0FDH
MMXDEF pand, 0DBH
MMXDEF pandn, 0DFH
MMXDEF pcmpeqb, 074H
MMXDEF pcmpeqd, 076H
MMXDEF pcmpeqw, 075H
MMXDEF pcmpgtb, 064H
MMXDEF pcmpgtd, 066H
MMXDEF pcmpgtw, 065H
MMXDEF pmaddwd, 0F5H
MMXDEF pmulhw, 0E5H
MMXDEF pmullw, 0D5H
MMXDEF por, 0EBH
MMXDEF psubb, 0F8H
MMXDEF psubd, 0FAH
MMXDEF psubsb, 0E8H
MMXDEF psubsw, 0E9H
MMXDEF psubusb, 0D8H
MMXDEF psubusw, 0D9H
MMXDEF psubw, 0F9H
MMXDEF punpckhbw, 068H
MMXDEF punpckhdq, 06AH
MMXDEF punpckhwd, 069H
MMXDEF punpcklbw, 060H
MMXDEF punpckldq, 062H
MMXDEF punpcklwd, 061H
MMXDEF pxor, 0EFH
; define mmx shift instructions
MMSHIFTDEF PSLLW, 0F1H, 71H, SI
MMSHIFTDEF PSLLD, 0F2H, 72H, SI
MMSHIFTDEF PSLLQ, 0F3H, 73H, SI
MMSHIFTDEF PSRAW, 0E1H, 71H, SP
MMSHIFTDEF PSRAD, 0E2H, 72H, SP
MMSHIFTDEF PSRLW, 0D1H, 71H, DX
MMSHIFTDEF PSRLD, 0D2H, 72H, DX
MMSHIFTDEF PSRLQ, 0D3H, 73H, DX
; instructions not defined above
MOVD MACRO OP1, OP2
LOCAL X, Y
&MREGS <OP1>, <OP2>
X:
IF PAR1M
IF PAR2M
BSF PAR1, PAR2
ELSE
BSF PAR1, @WordSize PTR (PAR2)
ENDIF
Y:
ORG X+1
DB 06EH
ELSE
BSF PAR2, @WordSize PTR (PAR1)
Y:
ORG X+1
DB 07EH
ENDIF
ORG Y
ENDM
MOVQ MACRO OP1, OP2
LOCAL X, Y
&MREGS <OP1>, <OP2>
X:
IF PAR1M
IF PAR2M
BSF PAR1, PAR2
ELSE
BSF PAR1, @WordSize PTR (PAR2)
ENDIF
Y:
ORG X+1
DB 06FH
ELSE
BSF PAR2, @WordSize PTR (PAR1)
Y:
ORG X+1
DB 07FH
ENDIF
ORG Y
ENDM
EMMS MACRO
DB 0FH, 77H
ENDM
; purge temporary macros
PURGE MMXDEF,MMSHIFTDEF
ENDIF
.LIST
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -