The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Akash on December 31, 2011, 08:33:19 AM

Title: Getting Started
Post by: Akash on December 31, 2011, 08:33:19 AM
Sorry if I started this in the wrong place. Introducing myself, I'm not a beginner to Programming  :bg . I know VisualBasic, FreeBasic, C and Pascal. But, now I want to learn Assembly Programming. I couldnot find any file meant for beginners to Assembly in MASM32 Installation Folder. If I'm not wrong there should be one with proper guide for the beginners to ASM. So, could you please refer me to some PDF/CHM help files that can make me start reading and writing ASM.  :toothy

Thankyou ...   :8)
Title: Re: Getting Started
Post by: MichaelW on December 31, 2011, 08:53:57 AM
Try the \masm32\help folder, starting with asmintro.chm.
Title: Re: Getting Started
Post by: Vortex on December 31, 2011, 08:54:50 AM
Hi Akash,

Welcome to the forum.

Here are some links for you :

http://win32assembly.online.fr/tutorials.html

http://homepage.mac.com/randyhyde/webster.cs.ucr.edu/Win32Asm/index.html
Title: Re: Getting Started
Post by: Akash on January 01, 2012, 08:16:39 AM
 :U Thank you. I really appreciate your help. I had almost started learning Randy Hyde's HLA (The Art of Assembly Language) but I read someone criticizing it for being a bit Basic(ish) rather than ASM(ish). So I stopped it.

Thank you.  :cheekygreen:
Title: Re: Getting Started
Post by: jj2007 on January 01, 2012, 09:23:50 AM
Quote from: Akash on January 01, 2012, 08:16:39 AMI read someone criticizing HLA for being a bit Basic(ish) rather than ASM(ish).

What you write is misleading.
First, HLA belongs to the family of languages that require, for unknown reasons, semicolons at the end of each line (I am allergic against semicolons and brackets of all sorts)
Second, Basic (http://www.masm32.com/board/index.php?topic=12460) is a wonderful language provided it gets assembled with ml.exe or Jwasm :8)
Title: Re: Getting Started
Post by: braincell on January 03, 2012, 02:37:09 AM
Hi,

I also just wanted to introduce myself and say I'm not a bot.
I'm going to construct my question and post a topic tomorrow.
I'm really glad I found this forum, I'm quite new to ASM.

Cheers

Title: Re: Getting Started
Post by: anunitu on January 03, 2012, 04:45:01 AM
Assembly is not really hard,as Hutch says assembler in a windows environment is much easier than the old DOS assembler,you had to understand memory segments, and if you wanted something like a GUI,you would have to grind yourself some code to make it happen.
Title: Re: Getting Started
Post by: dedndave on January 03, 2012, 12:04:58 PM
DOS wasn't that hard, really
it's not like you need to be a math major to grasp segmented addressing

what makes modern programming difficult is the OS - much more complex
but then, for every additional thing there is to learn, there are more features available
Title: Re: Getting Started
Post by: Akash on January 05, 2012, 05:51:06 AM
QuoteWhat you write is misleading
Sorry if it is/was offensive. But, someone wrote it that way.

Quotesemicolons at the end of each line
:thumbu I agree with you but, they can be helpful when writing multiple statements on line (in C, Pascal).

QuoteSecond, Basic is a wonderful language provided it gets assembled with ml.exe or Jwasm
I am not talking about MASMBasic but, I am one of those lazy people who is just too tired with EndIF  :'(


I am not a Programmer (and am/was not a Computer Science Student either) though I have plan(s) to specialize in IT in the future  :wink . But, got interested in programming somehow and am addicted of it. ASM has and gives power one can't get any with other languages. :bdg

But, which one is better amongst MASM and FASM ? FASM seems quite a popular choice among many people.
Title: Re: Getting Started
Post by: jj2007 on January 05, 2012, 06:50:51 AM
Quote from: Akash on January 05, 2012, 05:51:06 AM
QuoteWhat you write is misleading
Sorry if it is/was offensive. But, someone wrote it that way.

I was just joking, Akash. Welcome to the Forum :thumbu
Title: Re: Getting Started
Post by: Akash on January 17, 2012, 08:32:30 AM
Please accept my apologies for reviving this (almost)dead-thread. But, I read some intro files and got that mov copies data/values into registers.

ecx is a 32 bit register. Just for example:

var
    i : integer;

begin
i := 2;  // i equals 2
end.

then, in MASM, it should be (i suppose,)

mov ecx, 2

but, what is ecx ? This is my question which none of the help files seem to answer. I mean, it is a 32 bit register (in memory,) but, what should I supose ecx should mean?
I mean where will ecx store my 2. Just like i := 2 in Pascal (i stores 2). And, most importantly, when should I figure out what register to use when I have to store something else like characters and others ? When should I understand that I should use ebx,edx and others. When I mov a value into a register (like ecx) and then if I use ecx again, will the ecx be overwritten ?

The only thing I understood as I read Assembly are PUSH and POP.
Sorry for this stupid question/s. But, this is what is making me feel my question is stupid.

Thanks ..


Title: Re: Getting Started
Post by: dedndave on January 17, 2012, 11:39:57 AM
ECX is a one of the "general" registers in Intel 32-bit CPU's
the general registers are named EAX, EBX, ECX, EDX, EBP, ESI, and EDI
another register is ESP - the stack pointer
and another is EIP - the instruction pointer, which you cannot access directly
EAX, EBX, ECX, and EDX may also be accessed as words or bytes

(http://www.programming.msjc.edu/portals/19/Images/Registers.png)

they are really just names, but they do have some meaning

EAX - accumulator (EAX and EDX are typically used to hold data)
EBX - base index (may be used to hold addresses - on newer CPU's all general registers may be used to address data)
ECX - count (may be used to hold the iteration count for loops)
EDX - data (sometimes, EDX and EAX are used together to hold 64-bit values)

EBP - base pointer (typically used to hold a stable location on the stack)
ESP - stack pointer (used to hold the current stack location)
ESI - source index (may be used to hold the address of a "source" string)
EDI - destination index (may be used to hold the address of a "destination" string)

EIP - instruction pointer (the location of the next instruction to be executed)

there are several other regsiters for the FPU and SIMD instructions, as well as "segment" registers
for now, worry about the ones listed above   :P

here is some suggested reading - start with chapter 1
http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/toc.html
Title: Re: Getting Started
Post by: mineiro on January 17, 2012, 12:13:30 PM
Ecx is a register Sr Akash, and a register is suposed to store some numbers. (binary numbers or if you like, hexadecimal numbers).
You can think in the same way if you have a shoebox. Each box have (or not) shoes inside it, and if you are talking about 16 bits registers, so you can have 16 shoes inside that box, in your case, you are talking about a box that can hold 32 shoes. In eletronic, we call this flip-flop.(a chip that can hold one bit (shoe)), but joined with others, can hold so much bits.
So, you have named that box with the name of "eCx", because you like to "Count", or "eAx", "Acumulator", or use that box with union (or not) of other box , so eBx(Base), or hold some Data(eDx) in that box. Playing with assembly you have freedon to store numbers in any box that you like, but some instructions(mnemonics) are registers specific. Read about "loop" instruction and you will see that the number stored in "ecx" will be decremented each time.
Your question is when numbers will be numbers, and when numbers will be data, because all inside computers are numbers. We define this, the programmers.
An example is; the number "30" in hexadecimal, can be some counter, so it will be a number (signed or not), but if you throw this number to screen, you will see a representation of 0 (yes, that zero that you are reading) number, so the number will be data.

Quote from: Akash on January 17, 2012, 08:32:30 AM
When I mov a value into a register (like ecx) and then if I use ecx again, will the ecx be overwritten ?
Yes, but you can save ecx before changing it using "push" and after, restore it using "pop"


mov ecx,2              ;ecx after processed = 2
push ecx                ;saving ecx in stack
mov ecx,1              ;after processed ecx=1
pop ecx                 ;after processed ecx = 2

Title: Re: Getting Started
Post by: FORTRANS on January 17, 2012, 12:56:37 PM
Hi,

   A register is a piece of memory with some special features
added on to it.  Like any memory location, you can store and
retrieve values in it.  And you can do logical and arithmetic
operations on its contents.  A register is special in that it is built
into the CPU and has added functionality, like being used for
addressing or indexing memory external to the CPU.

Regards,

Steve N.
Title: Re: Getting Started
Post by: Akash on January 18, 2012, 12:14:02 AM
Thank you all for the help. I really appreciate it.  :thumbu

Looks like I really have to continue with THE ART OF ASSEMBLY LANGUAGE Book.  :eek Too  bad for me that I stopped it the last time ..  :(

And I suppose this (attached picture in zip) one is just a false positive of Avira Antivirus. Am I right ?
Thank you all ..
Title: Re: Getting Started
Post by: bomz on January 18, 2012, 05:09:32 AM
http://www.emu8086.com/ (http://smiles.kolobok.us/light_skin/tender.gif)
http://i058.radikal.ru/1102/64/eea23a98dc88.gif
Title: Re: Getting Started
Post by: Akash on January 18, 2012, 06:56:03 AM
 ::) Hey, maybe I am catching up with Assembly. Okay here is what I have understood. Registers are just places in memory, I need to understand the meaning and significance of the registers and use them accordingly for storing values and use those values by moving them here and there. And I don't get those features I used to get in HLLs and registers are there just so that I can use them for storing suitable values / datas. And, .. and .. well that's it. And, understand certain meanings of the instructions.
So, what I use and when I use is the logic of Assembly. Am I right ?  :8)
Title: Re: Getting Started
Post by: avcaballero on January 18, 2012, 10:34:09 AM
Using registers is much more quickly than memory accessing, so you should use registers as much as you can. Also, they are a way to shared data with procedures ... Also they are needed to math operations, etc.
Title: Re: Getting Started
Post by: Akash on January 19, 2012, 03:55:23 AM
Its me again but, this time it is not another silly question. I have got the hold of assembly. Seems it is not as hard as I thought it is.  :green2

(1) Each register can not hold more than one values at a time. Am I right ?

(2) And, when I store some value in a register supp. ecx then, if I have some of my own function. What will be the register ecx in it be ? I mean, will the value in it be same as the one I have defined / stored earlier? (Will the value in it be affected by the function I call afterwards ? It won't be like it is in C.) Am I right ?

(3) When I store some value in eax, and then I call some procedure which (I learned,) will store the result (probably) in eax. So, I'm supposed to push it before I call the function so that I don't lose the information I stored in eax. Am I right ?

Thanks   :bg
Title: Re: Getting Started
Post by: dedndave on January 19, 2012, 04:12:34 AM
1) correct

2) the value in ECX will remain the same until some instruction changes it
this is true for all code in the current thread - a program may have more than one thread - but, that's an advanced topic

3) this is true
the trick is not to have important values in EAX, ECX, or EDX when you call a function, if practical to do so
those 3 registers are likely to be destroyed - the others are typically preserved in win-32 applications

sometimes, you may want to preserve one of those registers across a call
then use PUSH and POP
notice that you may want to do something with the value that the function returns in EAX, first
there are a few ways to handle this
one way is to PUSH a value from one register (let's use EAX), and POP it into another...
        push    eax
        call    SomeFunction
        pop     edx

the value that was originally in EAX is now in EDX
and the value returned by SomeFunction is in EAX
Title: Re: Getting Started
Post by: Akash on January 19, 2012, 04:50:02 AM
Looks like PUSH and POP are the parts of the Assembly's backbone. Thank you, I got it. :U

And, by the way, to create threads, we use the function CreateThread() in MASM32 (just as in any other HLL) or are there any inbuilt methods ?

::)

Thanks
Title: Re: Getting Started
Post by: donkey on January 19, 2012, 07:27:59 AM
Quote from: Akash on January 19, 2012, 04:50:02 AM
Looks like PUSH and POP are the parts of the Assembly's backbone. Thank you, I got it. :U

And, by the way, to create threads, we use the function CreateThread() in MASM32 (just as in any other HLL) or are there any inbuilt methods ?

::)

Thanks

CreateThread is part of the Windows API, not MASM32. Windows provides a rich set of functions that allow a programmer to properly interface with it and have it do things like create dialogs and windows, manipulate text and images, manage memory, create and execute threads and thousands of other mundane functions. You can call these functions via a LIB file that wraps the call to the containing DLL. Almost every DLL and OCX you see in System32 makes up a piece of the API, extensions to it can be found in various programs you install. The API is documented at MSDN:

http://msdn.microsoft.com/en-us/library/ff818516.aspx

Edgar
Title: Re: Getting Started
Post by: Akash on January 19, 2012, 01:34:19 PM
QuoteCreateThread is part of the Windows API, not MASM32. Windows provides a rich set of functions that allow a programmer to properly interface with it and have it do things like create dialogs and windows, manipulate text and images, manage memory, create and execute threads and thousands of other mundane functions. You can call these functions via a LIB file that wraps the call to the containing DLL. Almost every DLL and OCX you see in System32 makes up a piece of the API, extensions to it can be found in various programs you install. The API is documented at MSDN:
 
:eek
Thank you but, that is something which I already know. You misunderstood my question ..

I just wanted to know if the use of CreateThread() function exported by Kernel32.DLL is the only method through which the threads can be created in MASM32 or if there are any inbuilt methods (provided by Assembly Programming Language itself). I myself don't think that there are any Assembly Language inbuilt methods for threads creation but, asked just so.

Title: Re: Getting Started
Post by: donkey on January 19, 2012, 01:59:38 PM
Quote from: Akash on January 19, 2012, 01:34:19 PM
I just wanted to know if the use of CreateThread() function exported by Kernel32.DLL is the only method through which the threads can be created in MASM32 or if there are any inbuilt methods (provided by Assembly Programming Language itself). I myself don't think that there are any Assembly Language inbuilt methods for threads creation but, asked just so.

There are none, Assembly has no built in functions though Hutch's MASM32 package might have something it would simply be a wrapper for CreateThread, I haven't looked at the package in many years.