views:

606

answers:

8

Is it possible to create, edit, link, compile (is compile the word?) etc. assembly code in MSVC++?

Also, if it's not possible, how can I create an .exe out of plain text, ie: convert the text into whatever format is required to use assembly code, then turn the assembly code into an .exe. (I'd say compile, but I don't think that is the correct word here).

And finally, what are some good places to begin learning assembly code? Written in a way that someone who has little experience can use.

I know some of these questions are probably very stupid, but I have absolutely no experience in assembly code and am not exactly sure where to start.

+7  A: 

On x86, yes. You can use the __asm keyword to put assembly inline in your standard source files, and use the normal MS compile/link tools to compile everything together.

On x64 (or x86), you may need to use the ML and ML64 command line compilers for assembly.

Reed Copsey
This only works on x86, and will cause you pain switching to x64. The x64 compiler doesn't support inline assembly.
Michael
True: On x64, you need to use ml.exe.
Reed Copsey
@Michael: Updated my answer to clarify.
Reed Copsey
Anyone know *why* it isn't supported on x64?
Justicle
FYI: ML is in \VC\bin, e.g. D:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\ml.exe. This directory may not be in the path if vsvars32.bat has not been run.
Peter Mortensen
A: 

Look for information on the C++ 'asm' keyword. It may be compiler specific, but I know VC++ supports it.

Jherico
+1  A: 

In short, yes.

According to Wikipedia, MASM has been shipped with all versions of Visual C later than VC6, and is also available in the Windows Driver Developer Kit. Versions supporting 16-bit real and protected modes, 32-bit, and 64-bit are all supported.

RBerteig
+3  A: 

Visual Studio provides the __asm keyword for compiling inline assembly in c and c++. There is also a good discussion here on the use of inline assembly. However if you are just talking about compiling assembly on it's own I'm not sure if Visual C++ is the correct tool however I'm pretty sure visual studio ships with the MASM assembler.

Kevin Loney
+1  A: 

You can use the __asm keyword to write inline assembly.

pcasm-book(pdf) is a good tutorial to start assembly code programming.

Dani van der Meer
I don't know if it makes any difference, but a later version of the pcasm-book can be found at http://drpaulcarter.com/pcasm/pcasm-book-pdf.zip. 2005-03-20 vs. 2006-07-23.
Peter Mortensen
A: 

Does anyone read the previous answers? Is this the result of involving "points" and a total score ?

ryansstack
+1  A: 

Yes, sort of.

C:\Program Files\Microsoft Visual Studio 9.0\vc\bin>ml
Microsoft (R) Macro Assembler Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: ML [ options ] filelist [ /link linkoptions]
Run "ML /help" or "ML /?" for more info

You'd use the macro assembler. I don't know if Visual Studio will automatically "do the right thing" with .asm files, though, but you can certainly edit them with it and assemble them with ml.exe.

A good place to start learning assembly language might actually be by learning about reverse engineering.

Rob K
A: 

Some pointers re. useful reading/places to learn can be found here:

http://stackoverflow.com/questions/572818/best-book-to-learn-windows-assembly-programming/

PhiS