Hello all,

I've been programming in HLLs for several years, and I'm finally biting the bullet and jumping back into assembly. (Thanks go out to Iczelion; I was in the same boat thinking that Win32 assy was a nightmare until I saw his site.)

My problem is this. I need to get ramped up on assembly language again, but all the tutorials I can find are either (a) Win32 tuts assuming the readers knows assy, or (b) 16-bit tuts that I can't get to assemble under masm32 7 or masm 6.14.

Is there anything out there that walks the reader through something like "Hello, world" in x86/DOS, including how to assemble and link the thing, and then goes on to explain much of x86 assembly in general?

I've started reading Randall Hyde's "The Art of Assembly Language", but I admit I'm swamped in it. I've read the first 150 pages and I still don't know how to make "You are dumb and smell funny" appear on the console--you might be surprised how useful a program like that would be. ;)

I'm a very hands-on type of learner, if I can assemble and test an idea I'll learn it much more quickly than trying to memorize pages of opcodes and notes. That said, I'll ask another, more direct question. How would I write a program snippet that reads the command line arguments and prints them back to the screen? Something like this program in C:

void main(int argc, char *argv[]) {

for(int j=0; j<argc; ++j)
printf("%d: %s\n", j, argv[j])
}


I *think* I can puzzle through this with Iczelion's tutorial that uses "invoke GetCommandLine" but I'd prefer to know how to do it without making any win32 calls.

Phew. Sorry for such a long newbie post. Thank you all in advance, and hello!

-Chalain
--
Objects in compiler are larger than they appear in VB
Posted on 2002-04-16 16:45:32 by Chalain

I *think* I can puzzle through this with Iczelion's tutorial that uses "invoke GetCommandLine" but I'd prefer to know how to do it without making any win32 calls.
You should write a DOS program if you don't want to use Win32 calls, imho. Why use windows, if your not going to use windows? :)
Posted on 2002-04-16 16:53:35 by bitRAKE
Have a look at my tutorials at www.MadWizard.org, they explain the basics of (m)asm(32) you need to know to get started with the windows API.

Thomas
Posted on 2002-04-16 16:59:15 by Thomas

You should write a DOS program if you don't want to use Win32 calls, imho. Why use windows, if your not going to use windows? :)


Well, ultimately, I want to do both. :-) I write a LOT of console-based apps and utilities as it is. For the nonce, however, want to understand the DOS underpinnings so that the higher-level code will make more sense to me. What, exactly, does GetCommandLine do, for example?

I'm one of those folks who has to pick apart every macro and function... otherwise I'll end up using it wrong. :-)

Thanks,

-Chalain
Posted on 2002-04-16 17:21:13 by Chalain

Have a look at my tutorials at www.MadWizard.org, they explain the basics of (m)asm(32) you need to know to get started with the windows API.

Thomas


PERFECT! Thank you!

* wanders off to read through the tutorial files...

-Chalain
Posted on 2002-04-16 17:26:58 by Chalain
Originally posted by Chalain
For the nonce, however, want to understand the DOS underpinnings so that the higher-level code will make more sense to me. What, exactly, does GetCommandLine do, for example?
WinNT & XP have no DOS under the hood.

As in life, when programming we need to learn to trust the code of another - weather that is your best friend or M$. Read the API reference and take it as truth until you learn otherwise. One of the reasons for the abstraction layer of the API is so you don't know what GetCommandLine does exactly - nor do you need to know. Use the interface that is defined for that function. This provides leverage of hundreds of man years of code - you can do things that you would never achieve by yourself in your lifetime. :)
Posted on 2002-04-16 18:11:45 by bitRAKE


What, exactly, does GetCommandLine do, for example?


since no one has answered, as simply as i can put it (and keep its meaning), it returns the address (a pointer) in the eax register that points to the beginning of a null terminated string (i.e. a string with a 0 byte at the end) which contains your command line. for example, if you type in:
myprog.exe -?
and GetCommandLine is called properly, it will return some value in eax that contains a pointer to the string:
'-?',0
where 0 is the null character.

oh yeah, good luck on your journey through asm programming :)
not to frighten you, but it can be quite a rough road at first... then what a joy it becomes! oh yeah - i'm also an HLL convert :)
Posted on 2002-04-16 21:15:49 by jademtech
Chalain,

A common assumption that many make when they start assembler language programming is that they assume that DOS is worth knowing.

16 bit code hangs together differently and has to accomodate differences like segment/offset addressing, limited instruction range and that you can write "pure" assembler code in DOS.

DOS uses system based interrupts to supply functionality and without it you have to write very complex code to do basic things like display data on the screen or file IO.

With win32asm, you have a far larger range of system based functionality, a greater range of instructions, far more power to do what you require and with cleaner and simpler code.

Because of the operating system design, you cannot even closed a program without using a system call so there is no point in pursuing "pure" assembler code, it just does not exist.

What I would suggest is when you have digested enough of Randy Hyde's work, start dabbling with the win32asm that is available. It can all be learnt and it has far greater support than the old DOS stuff.

Regards,

hutch@movsd.com
Posted on 2002-04-16 21:56:18 by hutch--

WinNT & XP have no DOS under the hood.


* stunned silence *

* opens mouth to say something, then stops *

* stares blankly *

Ho... lee... crap.

Whoa. Hang on, this is still settling in.

But... I think... I think I'm getting it.

Um, okay. So. As hutch just said, I just need to go straight into the win32asm stuff. Okay. Woo. Wow.

Sorry, this is forcing me to recompile most of my assumptions. :-)

Um. Okay. So, GetCommandLine *is* the "right" way to go about getting the command-line arguments. How do I print them out? I was expecting to do the int 21h (or whatever it is) thing.

For example, I'm reading through Thomas' tutorials, and I've got a bunch of questions about mov and xchg and stuff, and it would answer my questions perfectly if I could just print a couple of strings to the console, swap bits of them around, and print them back out again. How do I do this, or do I need to (ick) fart out a win32 message dialog?



BTW, thanks for the help. I would have been at this a LONG time before realizing that my XP box doesn't have DOS infrastructure.

Thanks,

-Chalain
Posted on 2002-04-16 22:44:43 by Chalain
Well since im procratinating for exams, and your looking for help, here is a simple console example code i wrote for you. I built it from the ground up, so its heavily commented and intended to teach you the *very* basics of consol windows, and MASM in general.

Covers with *some* extents:

.data?, .data, .code, start:, end start, end, includes, string declarations, 13,10 code, ExitProcess, StdOut, StdIn, swprintf, Beep, atodw, StripLF, push, pop, and mul.

And there is a free *beginners* tip as well :grin:

There should be enough examples through it to give you a good start on getting consol stuff working for you. To learn more, look over or study the sources of hutch's M32LIB (masm32.inc/lib). Its an excellent way to learn assembly practices as each source is typically one function, and already has a header to describe what it intends to do. From there, mentally disassembly the source till you understand how the asm is being used....

Enjoy!.
:alright:
NaN
Posted on 2002-04-17 00:13:10 by NaN

Have a look at my tutorials at www.MadWizard.org, they explain the basics of (m)asm(32) you need to know to get started with the windows API.

Thomas


This is a very good set of tutorials for begginers .... a very good job and thanks alot Thomas ...

just one question for Thomas ...
are you planning to include more tutorials in the near future ... I was realy disappointed to know that tutorial 14 is still under construction ....:)

I'm really looking forward to it if your thinking about including more tutorials ...:alright:
Posted on 2002-04-17 00:26:55 by code1101

Well since im procratinating for exams, and your looking for help, here is a simple console example code i wrote for you. I built it from the ground up, so its heavily commented and intended to teach you the *very* basics of consol windows, and MASM in general.


Goodness!

May you do well on your exams, you have earned the karma at least. :) Actually, I did something very similar to what you suggest about mentally disassembling source. I finally broke down and wrote my own C example, then disassembled it with my debugger. ;) I learned a lot, like being the first local var, and being parameters, and I was pleasantly surprised to discover that char *argv[] is a nice neat array of pointers just like I had hoped.

Then I pounded my head on the keyboard when I got to the bit about "call printf" in libc.lib.... heh, stupid C libraries.

So. Thankyouthankyouthankyou for this sample code. I had to force myself to stop fiddling with it to come back here and write this. :) *sigh* Somebody call ahead to the Betty Ford clinic, I think I'm about to become an assembly junkie. I *LOVE* this!

Cheers,

-Chalain
Posted on 2002-04-17 00:53:52 by Chalain
Chalain:just one question for Thomas ...
are you planning to include more tutorials in the near future ... I was realy disappointed to know that tutorial 14 is still under construction ....

I'm really looking forward to it if your thinking about including more tutorials ...


At tutorial 14 I started with the API basics but I stopped there because those tutorials would be just like Iczelion's, so there's no real use for them.

However if I will write more tutorials, it will probably about asm itself (useful tricks, common ways to do things etc), and not about the API. As that's the hardest part for most people. The API may seem a lot to learn but there's good documentation (if you have a fast connection, download the platform SDK, it's the most complete reference for everything you'll ever need when programming windows). There's a lot less info about (32-bit) asm itself.

If you did not already find them, take a look at the mosaic tutorial, this tutorial learns you to actually use asm to build a program. View it online instead of downloading it, the new layout is easier to read.

Thomas
Posted on 2002-04-17 01:38:29 by Thomas
NaN:
Your sample program says:

This is the lesson: NEVER TRUST EAX, EBX, ECX, EDX, ESI, EDI to be Preserved after an API call, or in general any function that is not yours!

You'd better make that EAX, ECX and EDX :grin:

Chalain: ebx, esi and edi *are* preserved by API calls, the others are not.

Thomas
Posted on 2002-04-17 16:31:48 by Thomas