IMUL Rb {Rb/Ms} B/w 011010s1 MdRegR/m {disp} {disp} data {data}
For constants, use the following 32bit MASM code:
mMulC MACRO pDest, pSrc, pConst IF pConst EQ 2 FIDNI pDest, pSrc shl pDest, 1 ELSE lea pDest, [pSrc*2] ENDIF ELSEIF pConst EQ 3 lea pDest, [pSrc*2+pSrc] ELSEIF pConst EQ 4 ;SHL pDest, 2 ;lea is faster lea pDest, [pSrc*4] ELSEIF pConst EQ 5 lea pDest, [pSrc*4+pSrc] ELSEIF pConst EQ 6 lea pDest, [pSrc*2+pSrc] ;Src x3 shl pDest, 1 ;(Src X3) x2 ELSEIF pConst EQ 7 IFIDNI pDest, pSrc ;if I can't get back to pSrc after ;overwriteing pDest (i.e. pDest is pSrc imul pdest, pSrc, pConst ELSE ;Thanks Tim Roberts, timr@probo.com lea pDest, [pSrc*8] sub pDest, pSrc ENDIF ELSEIF pConst EQ 8 lea pDest, [pSrc*8] ELSEIF pConst EQ 9 lea pDest, [pSrc*8+pSrc] ELSEIF pConst EQ 10 lea pDest, [pSrc*4+pSrc] ;Src x5 shl pDest, 1 ;(Src X5) x2 ELSEIF pConst EQ 11 IFIDNI pDest, pSrc imul pdest, pSrc, pConst ELSE lea pDest, [pSrc*4+pSrc] ;Src x5 shl pDest, 1 ;(Src X5) x2 add pDest, pSrc ;((Src x5) x2) + Src ENDIF ELSEIF pConst EQ 12 lea pDest, [pSrc*2+pSrc] ;Src x3 lea pDest, [pDest*4] ;(Src x3) x4 ELSEIF pConst EQ 13 IFIDNI pDest, pSrc imul pdest, pSrc, pConst ELSE ;Thanks Tim Roberts, timr@probo.com lea pDest, [pSrc*4+pSrc] ; src x 5 lea pDest, [pSrc*8+pDest] ; src x 13 ENDIF ELSEIF pConst EQ 15 lea pDest, [pSrc*4+pSrc] ;Src x5 lea pDest, [pDest*2+pDest] ;(Src x5) x3 ELSEIF pConst EQ 16 IFIDNI pDest, pSrc shl pDest, 2 ELSE lea pDest, [pSrc*8] ;Src x8 shl pDest, 1 ;(Src X8) x2 ENDIF ELSEIF pConst EQ 17 IFIDNI pDest, pSrc imul pdest, pSrc, pConst ELSE ;Thanks Tim Roberts, timr@probo.com lea pDest, [pSrc*8] lea pDest, [pDest*2+pSrc] ENDIF ELSEIF pConst EQ 18 lea pDest, [pSrc*8+pSrc] shl pDest, 1 ;(Src X9) x2 ELSEIF pConst EQ 19 IFIDNI pDest, pSrc imul pdest, pSrc, pConst ELSE lea pDest, [pSrc*8] ;Src x8 shl pDest, 1 ;(Src X8) x2 add pDest, pSrc ;((Src x8) x2) + Src ENDIF ELSEIF pConst EQ 20 lea pDest, [pSrc*4+pSrc] ;Src x5 lea pDest, [pDest*4] ;(Src x5) x4 ELSEIF pConst EQ 24 lea pDest, [pSrc*2+pSrc] ;Src x3 lea pDest, [pDest*8] ;(Src x3) x8 ELSEIF pConst EQ 25 lea pDest, [pSrc*4+pSrc] ;Src x5 lea pDest, [pDest*4+pDest];(Src x5) x5 ELSEIF pConst EQ 30 lea pDest, [pSrc*4+pSrc] ;Src x5 shl pDest, 1 ;(Src X5) x2 lea pDest, [pDest*2+pDest] ;((Src x5) x2) x3 ELSE imul pdest, pSrc, pConst ENDIF ENDM
Note: On the Pentium II's imul may actually be as fast or faster! This macro is good for older chips.
file: /Techref/intel/x86/inst/imul.htm, 2KB, , updated: 2000/1/24 08:49, local time: 2024/11/8 15:40,
18.119.127.230:LOG IN ©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://www.massmind.org/Techref/intel/x86/inst/imul.htm"> intel x86 inst imul</A> |
Did you find what you needed? |
Welcome to massmind.org! |
Welcome to www.massmind.org! |
.