Question:
How do I run an X86 assembly program?
?
2013-09-09 11:31:16 UTC
I'm reading the assembly language for x86 processors and currently I'm struggling to run by assembly program. I've download the mas version 6 (the one that doesn't require you to have visual studio 2005) from www.bsit.zxq.net. I have visual studio 2012 and whenever i save my assembly program on notepad++ it opens up the code on visual studio 2012. However I can;t seem to get it to run and it's saying something about build errors. I'm probably doing it all wrong so can someone step by step tell me the best assembler to download for windows 8 64 bit (x64), and how to compile the program (I know it's not compiling cos it's assembly) and how to run it and view the results, such as as this simple hello world program:

.386
.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib

.data

msg db "Hello world!!!", 0
cpt db "MY FIRST PROGRAM!!!", 0

.code
start:

invoke MessageBox, NULL, addr msg, addr cpt, MB_OK + MB_ICONINFORMATION


invoke ExitProcess, NULL

end start

funnily enough the book i'm reading doesn't mention how to run the code so can somebody please tell me how to run an assembly program whilst i'm on x64 - although it should be the same as x86 since x64 can run any x86 program. Please help me out!!
Three answers:
anonymous
2013-09-09 14:04:42 UTC
EDIT:

I forgot to mention that you should have downloaded MASM32 from here:

http://masm32.com/

I don't know what that other MASM package you downloaded is, but it might not contain everything that you need for building complete Windows programs.

----------------



I'll get your program running and give you some good advice too.



The Windows API functions that have anything to do with strings are actually split into 2 different functions. In this case, there are MessageBoxA() and MessageBoxW() functions. The MessageBoxA() function is for strings with single byte ASCII character strings. MessageBoxW() handles wide (i.e. 2 byte Unicode) strings. In your source code, change 'MessageBox' to 'MessageBoxA'



With C/C++, you can either call the proper 'W' or 'A' API function directly or you can set a #define and the compiler will select the proper single byte or wide character function. By default, single byte strings are assumed, so a function call to MessageBox() would be translated to MessageBoxA(). Sometimes my programs have a mix of wide and single byte strings, so I always write the specific 'A' or 'W' function names.



Unlike C/C++, MASM only allows you to declare single byte strings variables, so to declare a wide string variable, you would have to do something like this:

hello dw 'h', 'e', 'l', 'l', 'o', 0

Use the MULTITOOL program in the \masm32 directory to help you write wide character strings.



To create an .exe program, you need to pass the .asm file to the assembler program (ml.exe), which creates an .obj (object) file. The next step is to pass the .obj file to the linker program (link.exe), which creates the .exe file. With Microsoft C/C++, you pass the .c or .cpp source file to the compiler (cl.exe) and then pass the .obj file to the linker (link.exe). To see a list of command-line parameters for the link.exe and ml.exe programs, use the /? parameter.



For both MASM32 and Microsoft C/C++, I use batch files for creating my Windows programs.

Here's what's in my MASM32 batch file (masm.bat):

--snip

\masm32\bin\ml.exe /c /coff /I\masm32\include /nologo "(program name).asm"



--snip



Here's what's in my linker batch file (mlink.bat):

--snip

"\masm32\bin\link.exe" /LIBPATH:\masm32\lib /INCREMENTAL:NO /NOLOGO /MACHINE:IX86 /SUBSYSTEM:WINDOWS,4.0 "(program name).obj"



--snip

If you are creating a console program (text output only), then you change 'WINDOWS' to 'CONSOLE'

Each of my Windows program and .dll projects have their own directory on the hard drive and I copy the 'default' batch files there and modify them accordingly. The directory names in the two batch file lines above have the hard drive letters omitted, but you may want to put in your own drive letter.

Just remember to modify the .asm and .obj file names in the batch files for your own programs.



Hints:

Change the '.386' to '.686' in your source file. You may need to use the Pentium CPU instructions later on instead of sticking with the limited .386 CPU instruction set.



Why are you using the 'NULL' word in your source code? 'NULL' equals zero, so it is easier to just type out '0' instead.



The 'addr' word in your source code can be replaced with 'offset.' I prefer to use 'offset' but I just mention this in case you come across other MASM32 .asm source files on the internet.



If you have never programmed with the Windows API functions before, then you MUST buy this book:

http://www.charlespetzold.com/pw5/

I learned Windows 3.1 (16 bit) programming from one of his books long ago, and I actually used assembly language instead of a Windows C compiler.

EDIT:

I found a link to a .pdf file of the book. You can view it online or download it.

http://ebookbrowsee.net/programming-windows-5th-edition-charles-petzold-ms-press-pdf-d188207548

-------

If you don't have the Windows API SDK, then you should download it from Microsoft's web site. It has the documentation for all of the Windows API functions, the .h and .lib files for C/C++ compilers, tools, and example programs. The API function documentation also tells you if a function has a wide character equivalent and which .dll file the function resides in.

http://www.microsoft.com/en-us/download/details.aspx?id=24826



Do you see your include and includelib lines? Instead of always having to figure out which .lib and.inc files to include, just declare a bunch of the most commonly used ones, like user32.lib and user32.inc, kernel32.lib and kernel32.inc, gdi32.lib and gdi32.inc, etc. Then remove the MessageBox line and the data lines and save the .asm file so it can be re-used as a template for your other Windows .asm programs.
?
2016-04-28 02:58:07 UTC
Learning the foundational examining abilities will allow your youngster to concentrate on understanding the topic they are examining rather than struggle with understanding the language finally leading to a far more worthwhile and satisfying reading knowledge and that is in what this program Children Learning Reading from here https://tr.im/QM4zl is based.

Children Learning Reading use methods to simply help your youngster study and improve his examining, awareness, and spelling capacity in the early college years.

Even though Young ones Understanding Reading plan relies about your son or daughter understanding the small appears which make up each term there are a few phrases in the English language that only can not be learned in this way (rhythm for example). In order to assistance one to teach your child these exceptional phrases an information is provided to the most common words that need to be trained by sight.

That bonus could be especially valuable if you and your youngster are experiencing a certain word. You realize that if the word is contained in the guide then it's a thing that can't be discovered applying the Children Learning Reading method.
anonymous
2014-09-13 19:36:48 UTC
Hi there,

You can download PDF Reader for free here http://bit.ly/1p6T7M2



If you need to open and read a PDF file PDF Reader is a perfect solution.



Cheers ;)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...