lea ecx, [ecx+ecx*4] ; ecx = ecx * 5
;***xor this one***
lea ecx, [eax+ecx*2] ; ecx = eax + old ecx * 10)
Thanks a lot!
-Milos
ASM basics.
Here are few ASM questions:
1) What are OFFSET & ADDR exactly doing, what is the difference between them?
2) What about square brackets, are they used for indexing array elements or for pointing to memory cells (or both)?
3) What is the logic behind this line?
-Milos
September 18, 2000 05:33 PM
1) - OFFSET gives the address of a variable relative to the beginning of it''s segment. ADDR...sorry I can''t remember.
2) - Indexing, just like in C What do you mean with memory cells?
3) - LEA sometimes is a bit confusing, but here it''s used for an optimized multiplication. A normal MUL or IMUL is very slow compared to these LEA instructions.
LEA stands for Load Effective Address, and deals with pointers - not their content!!! -
2) - Indexing, just like in C What do you mean with memory cells?
3) - LEA sometimes is a bit confusing, but here it''s used for an optimized multiplication. A normal MUL or IMUL is very slow compared to these LEA instructions.
LEA stands for Load Effective Address, and deals with pointers - not their content!!! -
What I thought by memory cells is this:
mov ebx, hFile
mov al, BYTE PTR [ebx]
Anyhow, thanks.
Can you explain me that LEA line please?
How is it actually working?
Thanks...
-Milos
mov ebx, hFile
mov al, BYTE PTR [ebx]
Anyhow, thanks.
Can you explain me that LEA line please?
How is it actually working?
lea ecx, [eax+ecx*2] ; ecx = eax + old ecx * 10
Thanks...
-Milos
-Milos
This post should be deleted, the actual post is below.
Thanks
Edited by - Topgoro on September 19, 2000 7:16:07 PM
Thanks
Edited by - Topgoro on September 19, 2000 7:16:07 PM
We emphasize "gotoless" programming in this company, so constructs like "goto hell" are strictly forbidden.
quote: Original post by Milos
Here are few ASM questions:
1) What are OFFSET & ADDR exactly doing, what is the difference between them?
2) What about square brackets, are they used for indexing array elements or for pointing to memory cells (or both)?
3) What is the logic behind this line?
lea ecx, [ecx+ecx*4] ; ecx = ecx * 5 ;***xor this one***lea ecx, [eax+ecx*2] ; ecx = eax + old ecx * 10)
Thanks a lot!
-Milos
Hi all.
1) Here is a quote from MASM help about ADDR:
"ADDR label passes the address of
[label] (segment and offset if DWORD, segment only
if WORD) to the procedure."
Where [label] is a symbol representing a function or subprocedure.
2) Baskuenen, I am afraid that is not quite correct. It is indexing, but not "just like in C". For instance, in C you can have the following structure:
In C:
struct TestStruct{ int Foo; int Bar;}
And in ASM:
TestStruct struct Foo dword Bar dwordTestStruct ends
In C you can write this to refer to the second instance of the TestStruct structure:
TestStruct SampleStruct;SampleStruct[1].Foo = 0;
In assembler, however, writting this:
SampleStruct TestStruct <>mov SampleStruct.Foo[1],0 ; Totally wrong
Will set the 3 most significant bytes of the parameter "FOO" and the least significant byte of hte parameter "Bar", in the *FIRST* instance of the structure array to zero.
In C the indexes are interpreted as a function to rhe size of whatever you are trying to index. In Assembler the index is *ALWAYS* in terms of bytes.
So in assembler you need to write:
SampleStruct TestStruct <>mov SampleStruct.Foo[8],0
Or better yet, to address any element in the structure array:
SampleStruct TestStruct <>mov eax,sizeof(TestStruct)mul Index ;multiplies EAX * Index, stores least signifincat dword of the result in EAXmov SampleStruct.Foo[eax],0
3)While in the mov instrcution:
mov ecx, [eax+ecx*2]; ecx = eax + old ecx * 10
the eax register is added the product of ecx multiplied by 2, and then the resulting value in eax is used as an addrees from which a double word is read and then stored in the ECX register.
This istruction "lea ecx, [eax+ecx*2]" will do the same thing except that the resulting value eax is the one stored in ecx, and not the value of any memory location the value in eax might represent.
Please note that the value of any registers inside the brackets [] is changed after executing any this 2 instructions (unless of course, it also happens to be the destination register, like in this case).
Hope that helps clarify, later...
Topgoro
;You are not a real programmer until you start all your sentences with a semicolon
Edited by - Topgoro on September 19, 2000 7:20:51 PM
We emphasize "gotoless" programming in this company, so constructs like "goto hell" are strictly forbidden.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement