The MASM Forum

Specialised Projects => Compiler Based Assembler => Assembler With Microsoft Visual C => Topic started by: bl4z0r313 on June 05, 2012, 08:27:08 AM

Title: Comprehensive x86 instruction set for MSVS2010?
Post by: bl4z0r313 on June 05, 2012, 08:27:08 AM
Something I've been wondering - is there a list anywhere of all the instructions Microsoft Visual Studio 2010 uses when compiling to .asm? I have some projects in mind involving using these files as input for some tools utilizing AsmJit - but AsmJit doesn't cover all of the obscure and rarely used x86 instructions. The OCD in me would like to know that these tools will never hit any hangups because of this - and it would be nice as well to not have to waste time writing extra code for instructions I won't have to parse anyway.

Thanks!
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: jj2007 on June 05, 2012, 10:10:52 AM
Try the following:
- download the "combined volumes" from http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html
- select all, copy, paste into a text file named "IntelComplete.txt" (ca. 8MB)
- use & modify the snippet below to get the instructions:
Quoteinclude \masm32\MasmBasic\MasmBasic.inc   ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  NanoTimer()
  Recall "IntelComplete.txt", L$()
  xchg eax, ebx
  push ebx
  Print Str$("Reading %i lines ", ebx), Str$("took %i ms\n", NanoTimer(ms))
  NanoTimer()
  Open "O", #1, "InstructLines.txt"
  xor edi, edi
  xor ebx, ebx
  .Repeat
   mov esi, L$(ebx)   ; get one line
   .if Instr_(esi, "—")   ; thanks, Intel, for a clear marker ;-)
      .if edx>3 && edx<10
         mov ecx, Instr_(esi, ". . .")   ; strip the dots
         dec ecx
         mov al, [esi]
         .if al>="A" && al<="Z"
            Print #1, Str$("\nLine %i\t", ebx), Left$(esi, ecx)
            inc edi
         .endif
      .endif
   .endif
   inc ebx
  .Until ebx>[esp]
  pop eax
  Close
  Inkey Str$("Writing %i lines ", edi), Str$("took %i ms\n", NanoTimer(ms))
  Exit
end start
Output:
Reading 176194 lines took 24 ms
Writing 1615 lines took 44 ms
Results attached, it needs some manual cleaning. Example:
Line 21249 MOVAPD—Move Aligned Packed Double-Precision Floating-Point Values
Line 21250 MOVAPS—Move Aligned Packed Single-Precision Floating-Point Values
Line 21251 MOVBE—Move Data After Swapping Bytes
Line 21253 MOVDDUP—Move One Double-FP and Duplicate
Line 21254 MOVDQA—Move Aligned Double Quadword


HTH, jj
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: dedndave on June 05, 2012, 10:54:04 AM
ouch !   :dazzled:

i think the \masm32\help\opcodes.chm file has most of them
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: zooba on June 05, 2012, 11:38:13 AM
I don't think there's any way to safely assume any less than the full list. The generated code is an implementation detail, which means any update to the compiler could change the instructions used (as in, there is a limited obligation to retain backwards compatibility). In particular, optimised code will more likely use more of the rarer opcodes than unoptimised code.

Maybe your best option would be to gracefully fail when you hit an unknown opcode and provide an easy way for users to let you know? Even if you cover the full set, you're still playing a losing game as the chip manufacturers add more instructions. Whatever approach you choose, good luck!

Cheers,
Zooba  :t
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: dedndave on June 05, 2012, 11:59:13 AM
you could provide the base set by default
then allow the user to add them, as needed, in an INI file or something similar
this could also simplify your update process   :P
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: Mr Hippy on June 06, 2012, 02:57:55 PM
Are you talking about the generic x86 instruction set? x64? Enhanced-instruction sets? What?

VC++ supports x86/x64/IA-64 instruction sets, along with enhanced instruction sets. You just have to enable the option. Then you will be able to write the instructions inline.
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: hutch-- on June 06, 2012, 05:24:11 PM
Simple solution, include the full Intel instruction set and you won't get into trouble on Intel processors. It may be worth the effort to include the AMD specific ones as well.
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: jj2007 on June 06, 2012, 07:11:50 PM
Quote from: hutch-- on June 06, 2012, 05:24:11 PM
Simple solution, include the full Intel instruction set

Would be nice if Intel gave us the full set in a machine-readable format. I attach a manually cleaned version of what I posted above, but warning not all instructions in the "Combined set" at http://download.intel.com/products/processor/manual/325462.pdf bear the marker...
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: hutch-- on June 06, 2012, 07:25:04 PM
Here is a cleaned (cleaned) set ALA QE Global replace.  :biggrin:
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: jj2007 on June 06, 2012, 08:26:00 PM
Sorry, I forgot that QE doesn't display UTF-8 :(
Leaving the — (char 151) in has one advantage: You can specify e.g. CVT*— as a search term and get immediately
Line 21071 CVTDQ2PD—Convert Packed Dword Integers to Packed Double-Precision FP
Line 21073 CVTDQ2PS—Convert Packed Dword Integers to Packed Single-Precision FP
Line 21075 CVTPD2DQ—Convert Packed Double-Precision FP Values to Packed Dword
Line 21077 CVTPD2PI—Convert Packed Double-Precision FP Values to Packed Dword
Line 21079 CVTPD2PS—Convert Packed Double-Precision FP Values to Packed Single-Precision
Line 21081 CVTPI2PD—Convert Packed Dword Integers to Packed Double-Precision FP
Line 21083 CVTPI2PS—Convert Packed Dword Integers to Packed Single-Precision FP
Line 21085 CVTPS2DQ—Convert Packed Single-Precision FP Values to Packed Dword
Line 21087 CVTPS2PD—Convert Packed Single-Precision FP Values to Packed Double-Precision
Line 21089 CVTPS2PI—Convert Packed Single-Precision FP Values to Packed Dword
Line 21091 CVTSD2SI—Convert Scalar Double-Precision FP Value to Integer
Line 21092 CVTSD2SS—Convert Scalar Double-Precision FP Value to Scalar Single-Precision FP
Line 21094 CVTSI2SD—Convert Dword Integer to Scalar Double-Precision FP Value
Line 21095 CVTSI2SS—Convert Dword Integer to Scalar Single-Precision FP Value
Line 21096 CVTSS2SD—Convert Scalar Single-Precision FP Value to Scalar Double-Precision FP
Line 21098 CVTSS2SI—Convert Scalar Single-Precision FP Value to Dword Integer

Handy, isn't it?  ;)

Edit: Holy crap! I tried to be clever and used FoxIt Readers "save as txt" feature for the fat Intel PDF. It saves but in format CrCrLf. So I went for our friend from Adobe (you know, Acrobat, the one with the GPFs), version 8.1; first it tells me "unable to save", then it freezes for ten minutes after you click ok. Copying to the clipboard is apparently allowed, at least it appears in the menu, but the clipboard remains empty. Right now I am testing the option "Save as accessible text", whatever that means, and it is "Saving page 1800 of 4175", in very slow motion 8)
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: dedndave on June 07, 2012, 12:40:15 AM
Quote from: jj2007 on June 06, 2012, 08:26:00 PM
Holy crap!

is that Italiano or Deutsch ?
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: Greenhorn on June 07, 2012, 03:23:49 AM
Quote from: dedndave on June 07, 2012, 12:40:15 AM
Quote from: jj2007 on June 06, 2012, 08:26:00 PM
Holy crap!

is that Italiano or Deutsch ?
http://dict.leo.org/ende?lp=ende&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=on&spellToler=&search=holy+crap (http://dict.leo.org/ende?lp=ende&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=on&spellToler=&search=holy+crap)

But I think it's International.  :bgrin:
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: dedndave on June 07, 2012, 09:51:12 AM
that's probably what the Pope says when he stubs his toe or something - must be Italian   :biggrin:
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: hutch-- on June 07, 2012, 11:35:06 AM
A German pope living in the Vatican probably swears in latin.

Quote
Irrumabo quod nocere.
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: jj2007 on June 07, 2012, 12:04:57 PM
That doesn't look correct, Hutch, it should be sancti stercore (German->Latin) :bgrin:
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: dedndave on June 07, 2012, 12:13:02 PM
Hutch made me realize....
the Pope is German, living in Italy
Jochen is, too
and he seems to have the Latin down

hmmmm - i wonder if jj2007 is actually the pontif, hmself, keeping a low profile   :icon_eek:
if so, i guess he would know how the Pope swears

anyways - that would certainly explain all the MasmBasic stuff   :lol:
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: jj2007 on June 07, 2012, 01:34:26 PM
Quote from: dedndave on June 07, 2012, 12:13:02 PM
anyways - that would certainly explain all the MasmBasic stuff   :lol:

The only thing that is correct in your post is that MasmBasic is indeed a divine language :greensml:
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: hutch-- on June 07, 2012, 01:48:29 PM
This was not a translation of "Holy Crap", its what a Pope may say if he stubbed his toe in Latin.  :P

As this is a fully wholesome meeting place of assembler programmer, I will not post the translation to English.
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: jj2007 on June 07, 2012, 06:16:07 PM
Ok, before the whole thread gets shoved into the Colosseum (that's in Rome, by the way), here the latest tool to get the Comprehensive x86 instruction set extracted from Intel's 17MB PDF manual - 434 instructions, alphabetically sorted and nicely formatted :biggrin:

Reading 231843 lines from IntelComplete.txt took        21 ms
Writing 434 instructions (alphabetically sorted) took   26 ms


Most instructions are now captured by the parser (I love PDF :icon_mrgreen:)
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: hutch-- on June 07, 2012, 07:11:51 PM
JJ,

Its been a while since I have done it but you used to be able to save a PDF file as plain text which from memory similified extracting the mnemonic names and following data. Certainly far simpler than trying to extract it from PDF format.
Title: Re: Comprehensive x86 instruction set for MSVS2010?
Post by: jj2007 on June 08, 2012, 12:13:02 AM
Quote from: hutch-- on June 07, 2012, 07:11:51 PM
Its been a while since I have done it but you used to be able to save a PDF file as plain text which from memory similified extracting the mnemonic names and following data. Certainly far simpler than trying to extract it from PDF format.

Absolutely - that's what I'm doing :biggrin:

But still, it's not trivial:

Desired output (only once, and the most descriptive one, please):
CALL   Call Procedure
CBW/CWDE/CDQE   Convert Byte to Word/Convert Word to Doubleword/Convert Doubleword to Quadword
CLC   Clear Carry Flag

What you have to parse (these are only the lines that contain CBW/CWDE/CDQE and the marker ):
CALL—Call Procedure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-112
CBW/CWDE/CDQE—Convert Byte to Word/Convert Word to Doubleword/Convert
Doubleword to Quadword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-131
CLC—Clear Carry Flag. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-133
.... some thousand lines more ....
CBW/CWDE/CDQE—Convert Byte to Word/Convert Word to Doubleword/Convert Double-Vol. 2A 3-131
word to Quadword
#UD If the LOCK prefix is used.
.... some thousand lines more ....
3-132 Vol. 2A CBW/CWDE/CDQE—Convert Byte to Word/Convert Word to Doubleword/Convert Double-
word to Quadword
.... some thousand lines more ....


See updated attachment in Reply #18 above.