Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker!bloom-beacon!eru!luth!sunic!tut!santra!tuura!risto From: risto@tuura.UUCP (Risto Lankinen) Newsgroups: comp.sys.intel Subject: Undoc'd immediate MUL in 80X86 (incl.8086) Message-ID: <622@tuura.UUCP> Date: 14 Feb 90 09:26:35 GMT Distribution: comp Organization: Nokia Data Systems Oy Lines: 53 A little experimenting with Microsoft Macro Assembler version 5.10 and the instructions AAM and AAD revealed a neat way to do immediate 8-bit MUL and DIV on 80X86:s. The 'feature' is *ABSOLUTELY* undocumented by either Intel or Microsoft or any other organization associated. Who- ever uses it must consider the possibility of the instructions not working in a particular computer. I took the chance to use them in an application for personal use only, since the only computer they are used is my ow only, in which they work. I ran into this using the SYMDEB, with which I accidentally used 'u' to "disassemble" random address. The SYMDEB listed instructions like AAM 2B and AAD 2A . A little browsin of the Microsoft Press' 386-book revealed the op-codes for the AAM and AAD are D40Ah and D50Ah . The specified function for AAM is ( AL <- AL mod 10d , AH <- AL div 10d ) and for AAD ( AL <- 10d * AH + AL , AH <- 0 ) . Now, the 2nd byte of both opcodes is 10d . I tried replacing this byte by different values instead of 0Ah (=10d), and it still worked in a similar way. Then I made two macros for MS-MASM 5.10: bmul MACRO immed db 0D5h,immed ENDM bdiv MACRO immed db 0D4h,immed ENDM ... mov ah,octave mov al,note_number bmul 12 ; AL would now contain 12*octave+note_number for a MIDI application... ; the SYMDEB lists the previous instruction as ; AAD 0C The bdiv does essentially the same as "div ","xchg al,ah", so the advantage would be the immediacy of the division + different register output which is good for some purposes (nt to mention small space saving for perfectionists). The speed difference is not very significant. The bmul does a bit more: "mov temp,al","xchg ah,al","mul ", "add al,temp" and "sub ah,ah" . For the purpose in the example above this suits well, as it is used in an interrupt service routine and is rather quick and small compared to the 'complete' way. Once more, this habit is absolutely discouraged for programs that should work in different processors, present or future. As an added curiosity, and because I don't have such in my possession, I would like to know what happens, if you run this on a NEC Vprocessor. I have run it in 8086, 286 and 386 (full ver.), and it works in those all. terveisin: Risto Lankinen --