News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

A complete newbie and his questions.

Started by Valliko, May 02, 2009, 01:51:08 PM

Previous topic - Next topic

GregL

I agree that you should learn 32-bit first, then look into 64-bit and don't bother with 16-bit unless you have a specific need for it. 

x64 Windows is quickly becoming the standard on new PCs, but since the WOW64 emulator runs 32-bit programs very well (although a little bit slower), you've got plenty time to learn 32-bit first.  I think knowing x64 assembly language will be a good skill to have.


Valliko

Hey everyone.

So MASM is going quite good, been following Iczelion's tutorial now, and playing with the IF / WHILE loops in MASM a little bit on my own  :U

Anyways, i still feel quite confused on Assembler, the main reason why i created this thread was wheter or not there is only one assembler language to each processor, or if there is (as it seems to me) a load of different languages to a load of different assemblers.

How is it really? I've always believed that if you're on an Intel processor and you program Assembly, you write the x86 Assembly language and NOTHING else. Yet you can't write MASM on FASM, or FASM on NASM etc... why is that? And what Assembler uses the one and only x86 language then? xD

Thanks.

Valliko

I think i realised now that even thou there are some major, or minor differences between all those Assemblers they all use the x86 Instruction Set, am i right?
Then, in MASM's case, there is MASM macros, invoke for example? :D

What about the WHILE / IF loops? Are those macros too? How does a While loop look in pure assembly?

Thanks.

dedndave

First, you should understand the difference between "machine language" and assembler.
Machine language is determined strictly by the processor being used.
There is one for the 8051, one for the 6805, one for the 8080, and so on.
It is somewhat tedious to write code with hexidecimal values, although, I
think it is a good exercise that college students should do at least one time.

Now, Intel, as well as a few other manufacturers have thrown a bit of wrench into this
definition, as they have made several processors that use a "family" of instruction sets.
Intel's family is commonly refered to as "x86". It all started with the 8086 processor.
There are probably 100 different processors that will execute, for the most part, all
of the instructions used on the original 8086, PLUS additional instructions that vary
from one processor to another. The Pentiums that most of us use today fall into
this catagory. The hardware defines the machine language.

For any given processor or family of processors, assembler programs have been
written to make the task of creating machine language programs easier. But,
different programmers sometimes have different ideas about how an assembler
program should work, how the directives are defined, and so forth. That is why
there are different assembler programs for the x86 family. Also, some of them
cost money, some are licensed for limited use, some are open source, meaning
that the source code for the assembler is open to development by others.

I also want to add that there are cross-assemblers. These are programs that
allow development of programs for one processor, while operating on a system
that is using a different one. For example, I have cross-assemblers for the 8051
and 6805 processors that I can run on a machine that has a pentium in it. This
means I can write and assemble the code, that does not mean I can execute it.
That requires an emulator program. Normally, I might write a program for a
8051 and generate an EPROM from the assembled code. I can then use that
EPROM to run 8051 project hardware and test my code. I do not have an
emulator, so it is the only way to test it.




dedndave

INVOKE and IF/THEN/WHILE are assembler directives.
I guess, the original definition of a directive gets a little fuzzy, here.
Originally, a directive was a command that told the assembler how to act, but did not generate any code, on its' own.
The INVOKE and IF/THEN examples that you asked about are exceptions to this rule, as they can or do actually generate some code for you.
Bascially, they are time-saving steps that allow you to write code faster, and with less typing.
In many cases, they can also make code easier to read and, in turn, maintain by others.
I am no expert at using IF/THEN structures, as I use them only for macros.
The MASM32 libraries come with a full set of macros already defined, so I haven't had to write any for 32-bit code, yet.
As for INVOKE, it simply saves you some typing by passing parameters to a system call for you.

INVOKE SomeAPIFunctionCall, Parameter1, Parameter2, Parameter3

generates code that looks like this....

   Push Parameter3
   Push Parameter2
   Push Paramerer1
   Call SomeAPIFunctionCall
   Add esp,12

It passes parameters on the stack to the function call, then adjusts the stack pointer to discard them when done.

Most assemblers for 32-bit code seem to support the INVOKE directive, and I think they support it in pretty much the same way.
Notice that some programmers do not use INVOKE. Most do, I think. In many cases, there is a macro defined in MASM32 that does the INVOKE.
That gives you three ways to call the function that all look very different, even using the same assembler program.
There are nearly as many programming styles as there are programmers, and that is why programs you look at can appear so different and do the same thing.