Shoutbox

Programming Tutorial 1: Introduction to Assembly - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Programming Tutorial 1: Introduction to Assembly (/showthread.php?tid=37311)

Programming Tutorial 1: Introduction to Assembly by Ash_ on 01-22-2005 at 09:21 AM

Introduction to Win32 Assembly

OK!, welcome to the first tutorial of what i hope to be a few.

first we will sort out the things you need.
for all the tutorials i will be using the mASM32 Compiler get it from the mASM32 Website. it's a good compiler with no fancy features all text which is just what i like.

im not gonna introduce you to all of the operands and registers yet but i will describe what they are.

Register: a register is (how do i explain), its a computer wide variable which all API calls may use, i know i said i wouldnt introduce you to them all but 'EAX' is the most commonly used register.

Operands: these are like predefined functions, such as MUL, ADD, PUSH and POP. there are more but i find that i use these the most.

there are also functions called Macro's these are coded by you or are in the Macros.asm include file that comes with the mASM32 compiler.

ok first ill show you the code, then i'll go through it with you.

code:
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
Caption      db "w00t",0
Text      db "im the leet coder!",0

.code
start:
    invoke MessageBox, NULL,addr Text, addr Caption, MB_OK
    invoke ExitProcess,NULL
end start
quote:
all this does is popup with a messagebox saying "im the leet coder", it is pretty self explanatery but ill go through it anyway.

.386: ok this specify's the processor it will be built for, for this any 386 or above processor can run this!
dont worry bout the .model flat, stdcall. when i was learning someone told me to always keep this the same otherwise it might have trouble compiling with the 32-Bit linker.


include just includes the resources needed for your program from this file into the compiled exe.


includelib just includes lib files (created when dll's are created), these have the actual API functions inside of them (Y).
quote:
Originally posted by The Code Section

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

i used these includes because the MessageBox function requires the user32.lib file and ExitProcess requires the Kernel32.lib file.

'obtain' a API viewer and it will show you the lib file it needs to be called. these are the lib files you include in your code for it to compile correctly (Y)

.data ok, in Assembly ALL! variables must be declared (eg, you cant be like 'invoke MessageBox,NULL,"^.^","¬_¬",MB_OK' it simply will not compile in mASM32, other compilers might allow this though.)


Caption    db "w00t", 0 ok Caption is the name of the variable, db stands for 'declare byte' (eg dw (declare word) dd (declare dword)), "w00t" is what the variable contains and the 0 on the end (cant remember at this moment) null-stringed or something. ill edit when i remember :P.
.code starts the code


start just a name for the start of code,  code must be placed in between this and end start <-- which pretty much states itself.


invoke MessageBox, NULL,addr Text, addr Caption, MB_OK : ok here we go, invoke (same is call in some other languages), MessageBox: well we all know this API call. NULL, simple means nothing in this case its the Handle argument so this will not be inside any window at all. addr Text and addr Caption, ok when you declare a variable it gets stored in the memory of the program, thus allowing Trainer makers to say edit variables containing Money and Unit health but ill get onto that later. MB_OK simple a constant declared in the windows.inc include file which equals 0 which comes out as 1 'OK' button.


invoke ExitProcess,NULL this just end's the process, make sure you use this at the end of you programs otherwise you will get an error.


end start declares the end of the program

ok after all that said, feel free to PM me if you need to flame, correct or thank me.

if you want me to continue writing the next tutorial a simple PM would be very much appreciated otherwise i wont write it.

if enough people ask me to continue writing Assembly tutorials the next Issue will be "Coding our first window in ASM."

[EOF]


RE: Tutorial 1: Introduction to Assembly by Eljay on 01-22-2005 at 09:29 AM

nice tutorial Ash (Y)

quote:
Originally posted by Ash_
if enough people ask me to continue writing Assembly tutorials the next Issue will be "Coding our first window in ASM."

* Eljay asks Ash to continue :P
RE: Programming Tutorial 1: Introduction to Assembly by andrey on 01-22-2005 at 09:49 AM

quote:
Originally posted by leejeffery
* leejeffery asks Ash to continue
* andrey asks Ash to continue too

I was planning to take a look into asm, so (Y) keep it up :happy: