risto@tuura.UUCP (Risto Lankinen) (02/14/90)
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 <immed>","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 <immed>", "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 --
harlow@plains.UUCP (Jay B. Harlow) (02/15/90)
In article <622@tuura.UUCP> risto@tuura.UUCP (Risto Lankinen) writes: >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 Along the same note, this is what i found out.... 0d4h n ; aam - if n = 0ah, unpack - if n = 10h 0d5h n ; aad - if n = 0ah, pack - if n = 10h 0d6h ; lalc - load al with carry carry - al = 0ffh no carry - al = 0 i came across 0d6h, by looking though my roms, ( best way to find out how they do what they do....) and keep seeing 'db 0d6 ??' these three i have tried on a 8088, 80286, 80386sx, my guess is like the 'loadall' (which MS CV disassembles ;-) are for 'INTEL' use only... ha... loadall I can see reserving for thier testing but these are VERY handy. also ever notice that CV will disassemble xbts ibts ( extract bit string, insert bit string) but the 386sx can't execute them? are these simply instructions that were going to put in & didn't, or are they just on the 386 (haven't checked) are they there & have been moved? Inquiring minds want to know... Jay -- Jay B. Harlow <harlow@plains.nodak.edu> uunet!plains!harlow (UUCP) harlow@plains (Bitnet) Of course the above is personal opinion, And has no bearing on reality...
web@garnet.berkeley.edu (William Baxter) (02/15/90)
In article <622@tuura.UUCP>, risto@tuura (Risto Lankinen) writes: >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. This quirk is documented and supported by Eric Isaacson in his shareware assembler A86. (available on Simtel20) He claims that modifying the immediate operand to AAD has no effect on NEC V20 and V30 chips, as it is assumed to be 0Ah. William Baxter ARPA: web@{garnet,brahms,math}.Berkeley.EDU UUCP: {sun,dual,decwrl,decvax,hplabs,...}!ucbvax!garnet!web
david@csource.oz.au (David Nugent) (02/16/90)
> Message-ID: <622@tuura.UUCP> > > 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 This is actually documented and implemented in Eric Issacson's shareware 80x86 assembler "A86". A nice feature really, and it's a pity it didn't get documented. This won't work with certain brands of NEC microprocessors though, such as the V20 and V30. david -- uucp: ...!munnari!csource!david internet: david@csource.oz.au Via FidoNet 3:632/348, Melbourne, Australia.