Masm32
Sitting at a coffee shop this afternoon I had the privilege to eaves drop on a couple of guys discussing how Assembly Language is dead as far as writing desktop applications is concerned. Hmm Assembler was the golden word. The word that got me glued in on their conversation.

If that was not enough they were up about how it is only used in device drivers, cracking software, building parts of Operating Systems and Embedded Systems. So I decided to prove them wrong by doing something else other than what they mentioned and a Windows App was the most appropriate candidate.

So its not a good habit to listen in but I thought it makes a great intro to this article. This is not meant to be a tutorial on X86 Assembly but just to show how easy it is to make the basic “Hello World” program in Windows. In the days to come I will probably have to compile a tutorial on X86 Assembly because I will use some terms here which will not be understood and the tutorial will explain this better.

For now let us focus on getting our program to run. I will assume in this article that you have some experience in programming. I am not talking about Server-side scripting. I am talking about programming in a language that you would need to go through the program-compile/build/assemble cycles because we are going to do exactly that and I will not be explaining what building, assembing or compiling is.

The first thing to do when wanting to write any computer program is having the right tools. In this case we will use Masm32 which can be downloaded here absolutely free. The good news is that you wont need anything else; well other than a PC or laptop with Windows 2000 or higher. I am sure you already have that since you are already reading this post.

Once the Masm32 download is complete, you will need to install it. It is quite simple. Extract the zip file, choose the drive you’d like to install Masm32 to and start the process and follow through to the end reading the warnings as you go on. In some cases you will get false alerts from Anti Virus programs so you might wanna probably disable your Anti Virus Software before installing Masm32.

Now that Masm32 is installed, the next thing you would do now is open a new document (File -> New). Then type the following:

.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 1st Ms-ASM Program"

.code
begin:
invoke MessageBox, NULL, addr msg, addr cpt, MB_OK
invoke ExitProcess, NULL
end begin

Basically this is the entire code for our little program. To explain each of these lines, here goes:

.386

This tells the Assembler what Processor architecture we are targeting. In this case we are the targeting the 80386 family of processors. These Processors have 32 bit registers. Current processors from Intel and AMD fall under this category.

.model flat, stdcall

In this line the “model flat” tells the Assembler that we are not using the segmented memory model which if my memory serves me right had a memory limit of something like 1MB (1024 Bytes). Anyway that’s a story for another day. Now the “stdcall” tells us how we are going to pass parameters to functions which would be either from right to left or the usual way. In this case it is the usual way. Other calling conventions in addition to stdcall are c, syscall, basic, fortran and pascal.

option casemap:none

This tells us not to worry about being case sensitive. That sounds so Microsoft. Okay, moving on…

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

These lines include the necessary definitions and declarations that are crucial to the platform we are developing on so far as Operating Systems are concerned.

“Windows.inc” contains Windows Specific declarations and definitions.
“Kernel32.inc” and “kernel32.lib” contains kernel32.dll specific headers and library code
“user32.inc” and “user32.lib” contains user32.dll specific headers and library code respectively. This DLL is crucial when working with controls such as buttons, dialog, statics, textedits etc.

 

 

Related posts:

  1. A Brief Understanding of x86 Assembly Language
  2. How to Build and Install MariaDB on Windows From Source
  3. Benefits of knowing x86 Assembly Language
  4. How To Use A Windows Mobile Phone as a Modem
  5. How To Backup a MySQL Database With SQLyog
  6. Avoid problems when using .NET or other Technologies.
  7. Microsoft Security Essentials – Its About Time
  8. Qt vs MFC on Windows, Which is Best?
  9. How To Create MySQL Tables The Easy Way With SQLyog
  10. A Twenty Second Peek Into Microsoft Visual Studio 2010

 

Related Websites

  • FAQ about computer security Q: The virus blocked the registry access and how to get rid of it?A: You can deal with like this: 1. Click on Start -> Run (or Start Search in Windows Vista). 2. Enter GPEdit.msc and then press Enter. 3....
  • First Look: Windows Phone 7 Series Hands on Demo - Part 3 final This is it! What you've all been waiting for: your first look at Windows Phone 7. Corporate Vice President of Windows Phone Program Management Joe Belfiore gives us a full demo of the announcements being made today at Mobile World...
  • First Look: Windows Phone 7 Series Hands on Demo - Part 2 This is it! What you've all been waiting for: your first look at Windows Phone 7. Corporate Vice President of Windows Phone Program Management Joe Belfiore gives us a full demo of the announcements being made today at Mobile World...
  • Windows 7 Complaints Begin [/caption] Windows 7 Complaints Begin by David Goldman Wednesday, December 9, 2009provided by CNNMoney.com Users of the new operating system say the upgrading process is buggy. But once the kinks are worked out, customers are liking Windows 7 a lot...
  • 3 Apple a Day Diet Review Three apples a day is a creation of Tammi Flynn, who is a registered dietitian and a group training instructor at a well know gym establishment. Flynn found out that one of her clients was eating an apple before each...

 

 

8 Responses to “How To Program Windows 32 Using The Microsoft Assembler”

  1. Microsoft is not any stranger to having partners galore within the cellphone enterprise, but its lineup of producers for the upcoming, surprisingly promising Home windows Telephone 7 launch is no much less impressive. After loads of rumoring, Microsoft has confirmed that Dell and HTC will be making Windows Cellphone 7 telephones, in addition to ASUS, LG, and Samsung who had already been confirmed. All of these companies ought to have their stamp on hardware by the tip of the yr, with the launch of the OS nonetheless vaguely slated for the “holidays” We’ve got no doubt that all five manufacturers can construct some compelling, attractive hardware, however we’re notably enthused to see Dell really moving into the sport after the spectacular Streak and that drool worthy leak a little while back. learn more at http://www.wp7forum.com fans group.

  2. Nice website Reviews Newspaper Product Reviews

  3. Personally, I learned that migrating from Python version 2 to 3 was primarily a subject of relearning a few things: It for certain wasn’t as drastic a transfer as moving from Python to say the Java or Perl languages. Many of the changes have been long awaited, such as true division and changes to dict. Executing a print() is a whole bunch easier than System.out.println() in Java, so the learning curve is comparatively smaller and there are advantages to be realized.

  4. Thanks for great post! Will be bookmarking this article for future reference!

  5. Is definitely a really great article, thank you very much. I have saved this unique website to my own favorites.

  6. asko says:

    Hi HI First time skipped here on your site, founde on Yahoo. Thank you very much for the reassurance. I completely agree with you. I will discuss your answer with my partner. Thanks again.

  7. Issac Maez says:

    Hey, thanks for this one. I read it like five times and I laughed each time. Hah-hah!

  8. [...] This is not meant to be an in-depth tutorial on x86 Assembly but it is simply a follow up of the article on programming Windows 32 using MASM32. The mentioned article can be found here. [...]

Leave a Reply

    © 2003, 2010 Sobbayi's Tech Labs

Home Blog Home About Newsletter