News:

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

Some questions about Assembly Langauge

Started by Glen, August 25, 2007, 10:43:10 AM

Previous topic - Next topic

Glen

Hi All,

This is my first message, I dont know anything about asm language and want to ask some questions, if you please answer i will be very happy.

1) First of all, i downloaded masm32, but i can not compile sources i found on internet.

The way i do is:
ml filename.asm filename.obj  - > link filename.obj

It builds the examples you presented but i can not build the sources i wrote myself

2) Is "Programming language" a script that compilers understand and convert it to asm?

For example, if i want to create my own programming language, the only way to do that is to learn asm?

Example syntax
if i create a language that understands c = a + b
as
C equals A plus B;

Do i need to convert it to
mov eax a
add eax, b
mov c, eax


And save it as "filename.asm" then link the obj file to generate executable automatically by our software(compiler) ?
This means "compiler" ?
Or is there anything else to create a programming language?

Thanks for your replies.
Have a nice day

Mark Jones

 Hi Glen. May I first say that the number one thing which stops people from learning assembly language is biting off more than they can chew. Start off gradually if you want to learn and avoid frustration.

Quote from: Glen on August 25, 2007, 10:43:10 AM
1) First of all, i downloaded masm32, but i can not compile sources i found on internet.

The way i do is:
ml filename.asm filename.obj  - > link filename.obj

It builds the examples you presented but i can not build the sources i wrote myself

This is to be expected. There are many assemblers and assembler clones out there, and none of them support more than one syntax (and each seems to promote it's own syntax.) The best thing to do is start tinkering with the tutorials included with MASM32. That's your best source for working code.

The reason why other code doesn't work is complicated. Each user generally customizes things to their liking - file paths, libraries, macros, etc. Since assembler is such low-level code, there is little margin for syntax convention so basically the code has to be "just right" for any one assembler and configuration to assemble it. Couple that with the rich history of an assembler like MASM which has had many incarnations since the DOS-only days, and you'll soon see that assembler code is very specialized not only in terms of syntax, but also age. Some code found on the 'net is 20+ years old and surely will not work with MASM32, even though it is "true assembler."

MASM and MASM32 are two completely different beasts by the way. While MASM32 does use the MASM assembler, you could not assemble 32-bit code because ML.EXE does not come with any libraries. This is what makes MASM32 so spectacular - Hutch has spent years-- decades even-- maintaining the plethora of include files and macros in the MASM32 package. What this means is that you can write relatively high-level Windows code in MASM32 which ML.EXE could never assemble by itself. These libraries make MASM32 usable as a "programming language" while retaining the power of assembler.

Quote
2) Is "Programming language" a script that compilers understand and convert it to asm?

Good question. I would not say C for example is a scripting language, but the end result of any compiler is object code, which is the stuff ML.EXE produces and the processor can execute. C would take a statement like "x += y;" and cram the elements into a buffer along with all the other relevant statements in that C program, then optimize the contents and convert it into machine (object) code. So no, C is not a "scripting language" - C is a compiler.

There have been various attempts over the years at making assembler "easier" by using macros and whatnot, but the problem with this always is that each "advancement" in simplicity reduces the level of control and increases obscurity. Assembly programmers like assembly because it is what it is; no more, no less.

Quote
For example, if i want to create my own programming language, the only way to do that is to learn asm?

Example syntax
if i create a language that understands c = a + b
as
C equals A plus B;

Do i need to convert it to
mov eax a
add eax, b
mov c, eax


And save it as "filename.asm" then link the obj file to generate executable automatically by our software(compiler) ?

Well that's one way to do it, but it would be better to make the "program language" a compiler itself which does what ML.EXE does already and more. And that is to convert

    c = a + b

into binary code, something like

B801000000   ; MOV EAX,1
B902000000   ; MOV ECX,2
03C1         ; ADD EAX,ECX
; EAX now contains 3

which the processor can then execute natively (minus the comments of course.) Converting "c = a + b" into assembler mnemonics first is an unnecessary step; it would be much faster to convert the compiler's program directly into object code.

Have you checked out Randall Hyde's AoA? He's made a HLA language which might be what you're after. Check his posts out here in the Project Support Forums, HLA Forum. His main site is: http://webster.cs.ucr.edu/

One other thing you'll have to consider is the EULA which comes bundled with ML.EXE. It freely allows you to create programs assembled by ML.EXE and sell them, but redistribution of ML.EXE itself is prohibited; so is code assembled for other operating systems. If these are problems, then you'll have to use one of the many other assemblers such as GoAsm (decent libraries and tech support here, but different syntax) or LzAsm (closer syntax, but does not include any libraries.) Or one or more of all the others, such as RosAsm, XASM, GASM, NASM, FASM, ObjASM...

Hope that helps. Good luck in your experiments.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Glen

First of all Thanks very much for spending time to reply my questions..
Hmm so you mean advanced compilers does not change codes into assembly, they directly change to machine code!!
Oh my god.. How will i learn a coding system occuring by only hex's :)

I have seen HLA but i dont know which assembly is more low-level. For example (Please correct me if i am wrong) masm32, tasm, HLA all of them have different syntax (similar but not different) so which one is the most low-level?