The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Valliko on May 02, 2009, 01:51:08 PM

Title: A complete newbie and his questions.
Post by: Valliko on May 02, 2009, 01:51:08 PM
Hi! Im a 16 year old sweden who've been programming (mostly C and C++) for some time now, and recently been looking in to Assembler.

So the thing is i am really confused. The way i think of ASM is that theres one language for each CPU-family, but there seem to be a load of different "languages" only to x86.
MASM, TASM, FASM, NASM and so on.. I know theese are all assemblers, and not complete languages, but there seem to be a huge difference between programs written for the NASM assembler, and programs written for the MASM assembler. Why is that?

So really, how many x86 languages are there? Can i write a program for MASM which is still compatible with NASM? What assembler should i use?
I really need to sort theese things out.. Thank you.
Title: Re: A complete newbie and his questions.
Post by: dedndave on May 02, 2009, 03:19:58 PM
i understand your question perfectly - lol
before i settled on MASM, i looked at several others
i wanted to choose one that i could learn - and that has wide acceptance and use
i should mention that i am familiar with MASM 5.10 from the old days - 16-bit DOS world
that certainly affected my decision
i want to avoid telling you anything like "this one is better than that one"
rather, provide you with information and let you make the choice
what makes the code appear so different from one assembler to another is primarily the assembler "directives"
also, support for different macro structures vary, and some assemblers provide a simplified environment
in fact, i try to write my code so that it may be easily moved to a different assembler, if desired
that, of course, requires basic knowledge of all of them
well - that's not gonna happen anytime this year - lol
i have selected MASM to get used to writing 32-bit code
once i have a better grasp on that, i want to learn more about a few other assemblers
the ones that i am mainly interested in are FASM, NASM, and GoAsm
GoAsm is very similar to MASM, in many respects, with many improvements, from what i understand
it is basically an attempt to take control of the assembler development away from MS,
so that the actual programming community may decide what changes/improvements are made, rather than MS
GoAsm is gaining popularity very fast
FASM and NASM appear to provide simplified directive schemes - things to make it easier to understand and learn
in that regard, they have given up some functionality as a trade-off
i think, once i become more experienced, i will settle with GoAsm
but, for now, i want to stay with MASM because it is more widely used (i.e. i can learn from more sources)
if i were a beginner, i might choose FASM, although, it may be just as easy to use
GoAsm or MASM to start with, learning the complexities along the way
because you are familiar with programming basics already, you may want to take a similar approach
Title: Re: A complete newbie and his questions.
Post by: peaslee on May 02, 2009, 03:21:27 PM
Hi.

I'm new at this myself, so there might be someone who can give a better answer, but this is what I think I know.

Assemblers are complete languages. There are many "brands" of assemblers just as there are for BASIC or C++. I have only been using MASM32, so I can't speak directly to compatibility issues, but I understand that in general they are not compatible. You can, however, link together object code that has been created by different assemblers.

I hope that helps a little.
Title: Re: A complete newbie and his questions.
Post by: dedndave on May 02, 2009, 03:50:35 PM
i should also mention the difference between MASM and MASM32
MASM is the assembler program written by MS
MASM32 (which includes MASM) is a set of time-tested and widely used macros and liibraries
in other words, rather than using MASM, and developing all of your own macros and libraries,
much of the work is done for you, you have only to familiarize yourself with them
this collection of macros and libraries can make the code appear very different
other similar collections are WinASM and i think Kip Irvine has a set, as well
in fact, i use the MASM32 collection, but i also use Kip Irvines' instructions - understanding that there may be some differences
Title: Re: A complete newbie and his questions.
Post by: Valliko on May 02, 2009, 04:30:44 PM
Hi and thanks for the answers :)

Okay so im gonna look a little into FASM and GoASM aswell, they sound very interesting. Is MASM the most established assembler for Win32 today you think? If so, MASM would probably be the best to start with, just to learn the language and then maybe "emigrate" to another one of my taste :)

EDIT: FASM seems to be the most "basic" assembler if you compare to the other two, is that true? I think learning assembler without using macros etc would be best and that's actually what im really interested in, just pure assembly :)
Title: Re: A complete newbie and his questions.
Post by: dedndave on May 02, 2009, 05:11:23 PM
I think FASM may be the simplest to learn.
I might recommend it to someone who was totally new to programming,
or to someone who needs ASM to meet a college requirement only.
As I said, you already have a grasp of the basics.
What I wanted to avoid was learning a simplified assembler, then
having a difficult time with a transition to a more complete one.

I think MASM is the most widely used assembler. I am not really sure about that.
It has been around as long as any of the others (except maybe Intel ASM86).

This could change. Because GoAsm has so many similarities with MASM,
programmers who are familiar with MASM find it an easy transition to make.
In 5 or 10 years, GoAsm could well overtake MASM for popularity.
Maybe it has already - lol. It is hard to say, actually. There are different groups
of programmers; One group that prefers ASM as their primary language;
Another group that has to learn it for college, and may never use it again;
And still another group of programmers who primarily write in some other
language, but use assembler in isolated instances to speed up their code.
Each of these groups will have a different set of preferences.

I use MASM at the moment, because I know when I am ready, I can
make a transition to GoAsm with minimal difficulty. I want to learn the
MS directive set, first. I think GoAsm is a "super-set" of MASM. The guys
who write GoAsm and it's libraries all hang out in here and they would
be far more qualified to answer that question.

I think MASM or GoAsm may be the best for you, because what you
learn about them, you can also apply to your C programs.

If I am not mistaken, FASM and NASM have a few different conventions
that may not make that so easy.

MASM and GoAsm have a more complex set of directives. That does not
mean you need to learn them all at once to write code.
Title: Re: A complete newbie and his questions.
Post by: peaslee on May 02, 2009, 05:18:45 PM
Quote from: Valliko on May 02, 2009, 04:30:44 PMFASM seems to be the most "basic" assembler if you compare to the other two, is that true? I think learning assembler without using macros etc would be best and that's actually what im really interested in, just pure assembly :)

From what I've seen on the Internet, this is a controversial issue.  :wink

For example, MASM32 has a way of prototyping subroutines that allows type checking, etc. Pushing the wrong number or type of values on the stack yourself is a bug that can be hard to find, especially for someone new. So, is the use of the "invoke" command not real assembly programming? Who's to say.
Title: Re: A complete newbie and his questions.
Post by: Vortex on May 02, 2009, 05:20:03 PM
Valliko,

Have a look at Jwasm (http://japheth.de/JWasm.html), a Masm compatible assembler maintained by Japheth.
Title: Re: A complete newbie and his questions.
Post by: dedndave on May 02, 2009, 05:37:58 PM
INVOKE is essentially an assembler directive.
MASM is supposed to type-check it for you, but I have cross-typed parameters
several times (newbie learning) and MASM didn't say a word about it.
This is understandable, as the MASM program would have to know in advance
what was expected for every (including future) API calls, etc.

Title: Re: A complete newbie and his questions.
Post by: Mark Jones on May 02, 2009, 05:50:48 PM
Hi Valliko, welcome to the forum. :bg

I concur with Dave, MASM32 and GoASM are both very good and well-supported here. However, I would focus on only one assembler, whichever you choose. Assembly in general can quickly become overwhelming, so take your time.

The MASM32 package includes some examples, but is otherwise not designed for beginners, however Iczelion (http://win32assembly.online.fr/tutorials.html) made a geat series of tutorials.

GoASM (http://www.jorgon.freeserve.co.uk/) has its own webpage, complete with examples and tutorials. GoASM is a little more work to setup however, and doesn't come as a complete package. To remedy this, E^Cube has created a GoASM SDK (http://www.masm32.com/board/index.php?topic=11180.0).

Most of all, have fun. :bg

P.S. One last thing. 32-bit code is the recommended beginning point. 16-bit code is outdated, and 64-bit code is very difficult to implement in assembler currently.
Title: Re: A complete newbie and his questions.
Post by: Valliko on May 02, 2009, 07:56:53 PM
Hello and thanks again!

I've decided to download the WinASM IDE and run it along with MASM since MASM seems to be the established one when it comes to Win32.
I have Iczelion's guide aswell. I will probably return with a bunch of questions and error messages in a near future :D
Title: Re: A complete newbie and his questions.
Post by: GregL on May 02, 2009, 09:49:37 PM
Quote from: Mark Jones... and 64-bit code is very difficult to implement in assembler currently.

Oh come on, it's not that difficult, it's just different.

Title: Re: A complete newbie and his questions.
Post by: Mark Jones on May 02, 2009, 10:59:11 PM
Well Greg, perhaps I should have said that it is not user-friendly for beginners -- there are only a fractional percentage of posts here even pertaining to 64-bit code, let alone beginner questions in 64-bit. (Who is going to make the Iczelion equivalent 64-bit tutorials, hmmm? Are you volunteering? :bg) E^Cube also made a 64-bit SDK, but if you ask me, starting with 64-bit code is far more trouble then it is worth and would simply confuse the learner.

Still, I can respect knowing about 64-bit and how it is different from 32-bit, but anything other than an overview is counter-productive IMO. Learn the basics first... advanced topics later.
Title: Re: A complete newbie and his questions.
Post by: hutch-- on May 03, 2009, 04:58:51 AM
Over time 64 bit will get better tools and better OS support but there is just not enough of it around yet for either. Where the shift from 16 bit DOS is a complete concept change, 32 to 64 bit is not so if you know your way around 32 bit assembler, the shift to 64 bit in the future will be no greate melodrama.

RE: Assembler usage, MASM commands the lion share of the market and this will more or less stay this way for the remaining duration of 32 bit. There certainly are other good tools around in 32 bit from GAS to FASM to NASM and of course GoAsm but if you want the greatest code base and the best support, MASM has the runs on the board.
Title: Re: A complete newbie and his questions.
Post by: sinsi on May 03, 2009, 07:51:01 AM
Quoteif you want the greatest code base and the best support, MASM has the runs on the board.
As long as you program Win32 isn't it?

edit: err, I mean masm32, not masm

Title: Re: A complete newbie and his questions.
Post by: GregL on May 04, 2009, 08:42:50 PM
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.

Title: Re: A complete newbie and his questions.
Post by: Valliko on May 05, 2009, 01:02:53 PM
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.
Title: Re: A complete newbie and his questions.
Post by: Valliko on May 05, 2009, 02:48:12 PM
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.
Title: Re: A complete newbie and his questions.
Post by: dedndave on May 05, 2009, 02:55:46 PM
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.



Title: Re: A complete newbie and his questions.
Post by: dedndave on May 05, 2009, 03:27:21 PM
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.