First is using lea for math ops. I get it, but dont really know how to'use' it yet. ie:

``	lea	eax, [ecx + edx - 4]``

I will try to parse this. Please tell me if I'm right.

i=eax = final value

x=ecx
y=edx

i=x+y-4 right?

``	lea	eax, [ecx + edx *4]``

i=(x+y)*4 or i=x+(y*4)?

Next where can I find a MASM marco tutorial?
I've done the Google search"MASM MACRO tutorial" and get lots of:

"Microsoft MASM MACRO assembler tutorial"

With no mention of macros.

Next, has anyone written a program using jump to labels, not PROCS? Don't need prototypes huh? But it I guess it is a bad idea. Why?

Next is nevermind. Found the old post I was lloking for.

Thanks.
Posted on 2002-05-26 07:08:45 by ThoughtCriminal
lea eax,

i=x+y-4 right?

yes.

lea eax,

i=(x+y)*4 or i=x+(y*4)?

the latter. this is due to how addressing works on x86 cpus, you might want to check the intel instruction set reference for more info.
Posted on 2002-05-26 08:22:07 by Tola
Thanks for the confirmation Tola. I got it now.

Now anyone know where to find a macro tutorial?
Posted on 2002-05-26 09:21:54 by ThoughtCriminal
The masm documentation contains quite some good info on macros. There's an online version available somewhere, bitRAKE once posted the link to it (search for 'masm reference online' or something like that).

Thomas
Posted on 2002-05-26 09:39:26 by Thomas
Bookmarked.

Thanks Thomas
Posted on 2002-05-26 09:46:38 by ThoughtCriminal
QUOTE: "...the latter. this is due to how addressing works on x86 cpus..."

Sure that's how the addressing works, because that's following the IEEE formula standard, which you may remember as the "BODMAS" or "BOMDAS" Rule from your early school days.

Simply put, the multiplication is performed before the addition.
Posted on 2002-05-26 15:10:43 by Homer
EvilHomer2k, BODMAS is not the reason here - look at the instruction encoding. Why doesn't 'lea eax, ' or 'lea eax, ' work - it is because of the instruction encoding. The SIB byte allows one indexing register to be multiplied by 1, 2, 4, or 8 - it is Table 2-3 in the manual.
Posted on 2002-05-26 15:44:05 by bitRAKE
BOPDMAS?

Not sure were all talking about the same school days...

B=Brackets
P=Parathesis
E=Exponents
M=Multiplication
D=Division
S=Substraction

BPEMDAS or B. PEMDAS (as in a name of sorts)

What's with the "O" in BODMAS

Sliver

ps. I slept through many a math class lets see if I've slept through this one too :)

Sliver
Posted on 2002-05-27 00:12:27 by Sliver

Next, has anyone written a program using jump to labels, not PROCS? Don't need prototypes huh? But it I guess it is a bad idea. Why?

You mean using jmp/jmp instead of Call or Invoke /ret? Well... if it's called rarely enough that you can use jmp/jmp, why don't you just cut-and-paste the procedure where it should be executed directly?

Or if you mean Call a label: or label:: type label... well it's fine, really, but the source code's gonna look kinda nasty... depends on your style too though... besides you don't REALLY need to PROTO a proc that doesn't use any HLL-type arguments anyway... if you pass arguments by register for instance...
Posted on 2002-05-27 01:02:27 by AmkG
Yeah you could just have:

``````
jmp proc1:
return1:

proc1:
...
jmp return1
``````

but that's a lot messier than having an automatic mechanism like call/retn. It eliminates the need to track return addresses and come up with meaningful labels. It's also a lot cleaner to explicitly mark code that is used frequently.

Jumps on the other hand are mostly used for branching.
``````
cmp eax, [value]
jnz label1
...
jmp label 2

label1:
...
label2:
...
``````
Posted on 2002-05-27 07:41:21 by grv575