News:

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

Low-Level Assembly Tutorials

Started by ThexDarksider, June 10, 2009, 12:01:49 AM

Previous topic - Next topic

ThexDarksider

Are there any low-level asm tutorials? I'm a total n%b and all I've found is stuff that uses invoke commands but that makes me code in C... When I open a neato program written in lowest level asm I find these blocks of code like mov ax,bx and then lea eax,[dword ptr something] and I guess asm needs more commands in a row for what would be one line in C code (i.e. to open a file, C has fopen(); but in asm I need to PUSH stuff then CALL stuff, etc. and that's the part I just don't get :'(), so is there a good noob-friendly tutorial or explanation? Asm looks so spiffy, I wanna learn it. :toothy

Btw I'm not a spambot, that's how all my posts sound... People usually get used to it. :cheekygreen: :green2 :green2

Jimg

The one my Paul A. Carter looks pretty good.  Unfortunately, it's for nasm, but the basics are all there.

Slugsnack

look for nasm tutorials. i had the misfortune of having to use that language at school last term.. local variables and parameters can not be named but only referred to as offsets from ebp once the stack frame has been set up. but it sounds like that is the kind of stuff you are looking for

maybe if you are really interested, start ripping apart some of your C programs in OllyDbg and you'll get the sort of code you're looking for. it might be hard at first but that's how i learnt assembly

ps. personally i still think art of assembly is the best book for learning about assembly ( not necessarily learning how to code asm though )

ThexDarksider

Thanx for replies. I have a C compiler, I have OllyDbg, I'm gonna get on that :bg and I'll search for NASM tutorials.
I've already taken a look before at AoA but as far as I can see it's about HLA and that's not really what I'm interested in. :boohoo: What I just don't get is how to do operations in asm, as example, in C if I want to open a file I use fopen, kinda logical. But I saw once in ASM I need to push some zeros, then offset with file name, then some zeros again... Are those parameters or what? :toothy I don't really get it, should I learn those sequences by heart or there's some logic I fail to perceive? Well anyway I'm gonna look at Dr. Paul Carter's tuts now, whatever I read is gonna improve my knowledge since I don't really know anything in this field. :toothy I don't even know why am I so attracted to assembly, I guess there must be an explanation. :U

Farabi

Quote from: ThexDarksider on June 10, 2009, 12:42:18 AM
Thanx for replies. I have a C compiler, I have OllyDbg, I'm gonna get on that :bg and I'll search for NASM tutorials.
I've already taken a look before at AoA but as far as I can see it's about HLA and that's not really what I'm interested in. :boohoo: What I just don't get is how to do operations in asm, as example, in C if I want to open a file I use fopen, kinda logical. But I saw once in ASM I need to push some zeros, then offset with file name, then some zeros again... Are those parameters or what? :toothy I don't really get it, should I learn those sequences by heart or there's some logic I fail to perceive? Well anyway I'm gonna look at Dr. Paul Carter's tuts now, whatever I read is gonna improve my knowledge since I don't really know anything in this field. :toothy I don't even know why am I so attracted to assembly, I guess there must be an explanation. :U

Yes it is right, the pushed value can be mean many thing depend on what the API need it.
For example,

.data
x dword 0
y dword 0
test 25 dup (0)

invoke Test,x,y,addr test


On Flat Assembler where you are interested on it will be

lea eax,test  ; get the address of buffer named test
push eax    ; push it to stack
push y ; push y to stact
push x ; push x to stack
call test ; call it
add esp,12 ; we pushed 12 bytes to stack so the stack must be balancing to zero, current stack is -12

Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"


ThexDarksider

I think that is Iczelion's judging by the address but thx anyway, I didn't check Paul Carter's NASM stuff yet because I don't have adobe reader installed (lol) but I'll do it as soon as I get home, I believe that MASM and NASM are somewhat similar. :bg

Vortex

Hi ThexDarksider,

Try Foxit Reader 3.0 for Windows It's a small and fast PDF viewer. Not bloated like Adobe Reader.

ThexDarksider

I'm very thankful for that, I have ~100 MB left on my system drive, a small PDF viewer is just the thing I need! :green2

alax

Quote from: ThexDarksider on June 10, 2009, 06:45:49 PM
I'm very thankful for that, I have ~100 MB left on my system drive, a small PDF viewer is just the thing I need! :green2
i'm lucky than you~~ i still have 685mb free on my 2gb C:P 'cause i put almost everything in the second 2gb disk D: - ust leave masm,radasm & od in C:
and foxit is right what i need now, thanks for that

ThexDarksider

That reader is so cool, I downloaded the zip and didn't even have to install! :toothy

GregL

#11
Low-level assembly:  it boils down to this, instead of using INVOKE, push the parameters on the stack and call the function.  Instead of using any other macros, replace them with the equivalent code.

There are a few times when using push and call is advantageous versus INVOKE, and there are times when not using a macro is advantageous, but other than those times, I don't know why would you want to do this? 

You could go the next step and program with a hex editor and opcodes too.  ::)   :lol


KeepingRealBusy

ThexDarksider,

The way I learned the basics was to output the .cod file from a C compile. I guess, depending on the compiler, the output is mixed C source lines (as commentary), and the generated asm code. Experiment with optimization and see what the compiler does to simplify the code (for size and speed) (and remember, "beauty is in the eye of the beholder" when viewing the "simplified" code).

Then start looking at the many examples in MASM32 and read the timing forums in the lab.

Dave.

RickyS

I'd suggest downloading the trial for emu8086. It uses 16-bit MASM syntax, so the stuff you learn from using it will easily transfer to MASM32. Plus, the interactive debugger will teach you a lot. Nothing compares to seeing your code execute in slow motion, and seeing how each line affects the registers and stack as it does it.

hutch--

Tread carefully with the assumptions that 16 bit DOS software translates well to 32 bit assembler, as a matter of fact it does not. 16 bit DOS code suffered the ugly complexity of segment/offset addressing, severe restrictions on instruction use, no register preservation convention and the assumptions of a non-re-entrant architecture.

32 bit code is a joy in comparison, 4 gig linear addressing, nearly unlimited instruction choice apart from privileged instructions, a multitasking architecture where you have more than one process running at the same time, a manufacturer/OS vendor register preservation convention and this makes cleaner, simpler, faster and more powerful code. Also remember that under 32 bit Windows you have over 12000 system function available.

Leave DOS code where it belongs, on the scrapheap of programming history, don't waste your life and time with this old junk.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php