Win32 Assembly – Basics

w32
Template:

.386
.model flat, stdcall
option casemap:none

.data

.data?

.Const

.code
Start:
End Start

Description:

.386

It is the assembler directive, which tells to use the 80386 
instruction set. There are many predecesor of this like 80486,
80586,etc

.model flat, stdcall

It tells which memory model to use. Under win32, there is only one 
memory model i.e flat. Under DOS, memory is divided in 64k segments
but under win32, momory is devided in 4GB seg. Therefore, you need
not to take of segment registers under win32.

stdcall

This is used to tell, which convention is to be used, means in a 
function, parameters are passed left to right in stack or right 
to left and who will adjust the stack once function is finished 
it's procedure. Generally, parameters are passed right to left in 
stack and it is the duty to callee to adjust the stack.MODEL is an 
assembler directive that specifies memory model of your program. 
Under Win32, there's only on model, FLAT model.MODEL is an assembler
directive that specifies memory model of your program. Under Win32,
there's only one model, FLAT model.

option casemap:none

This tell to consider words differently except few identifiers.

Example:  name and Name are different

There are mainly two sections viz Data and Code section.

Data seciton is divided into 3 sections viz Data, .Data? and Const

.data

This section is used to declare the variables and initializing them 
here.

Example:  MessageTxt db "Hello World"

This seciton constitutes the size of executable.

.data?

This section is used for declaring uninitialized variables like 
buffer.

This section doesn't constitute the size of executable. Variables 
are initialized at runtime

.Const

This section is similar to .data section but with one condition i.e 
it is read only. So, once you declare here, then it can't be changed.

.Code 

As you would have already guessed what comes in this section. This 
section includes the whole logic of your program. 

Start:

End Start

Code Section begins with a label. It isn't need to be Start means 
you can name it anything but it should end with "End" keyword.

Note: If you have any doubt, ask in the comment section. It will help others also.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s