Valhalla Legends Forums Archive | Assembly Language (any cpu) | Discussions on The C/C++ Reversing Reference Thread

AuthorMessageTime
Skywing
[quote author=TheMinistered link=board=7;threadid=5407;start=0#msg60479 date=1084756897]
In C++, and many other languages, the compiler will generate the following code to access an item in an array:

[code]
mov eax, [arraybase+index*arraytypesize]
[/code]

arraybase is the pointer to the base of the array, index is the item in the array you are trying to retreive, and arraytypesize is the size of the type the array is declared as.

[/quote]
Note that it would probably be a lea there, not a mov. It's also not uncommon to see several leas if you are dealing with an array of structures.
May 18, 2004, 3:28 AM
Maddox
[quote author=Skywing link=board=7;threadid=5407;start=0#msg60609 date=1084850907]
[quote author=TheMinistered link=board=7;threadid=5407;start=0#msg60479 date=1084756897]
In C++, and many other languages, the compiler will generate the following code to access an item in an array:

[code]
mov eax, [arraybase+index*arraytypesize]
[/code]

arraybase is the pointer to the base of the array, index is the item in the array you are trying to retreive, and arraytypesize is the size of the type the array is declared as.

[/quote]
Note that it would probably be a lea there, not a mov. It's also not uncommon to see several leas if you are dealing with an array of structures.
[/quote]

Why would it be lea? It would depend on what the code is doing. It's not uncommon to see mov ecx, [array+index*size].
May 18, 2004, 9:57 PM
Adron
[quote author=iago link=board=7;threadid=5407;start=0#msg60487 date=1084760373]
For some arithmatic:

This C code:
[code]int edx = 3;
edx = edx * 2 + 5;[/code]

will probably look like this:
[code]mov edx, 3
lea edx, [5 + edx*2]
[/code]

lea's can be used for arithmatic.
[/quote]

Note that that particular C-code probably would be optimized to assign a constant to edx ;)
May 19, 2004, 10:18 AM
iago
[quote author=Adron link=board=7;threadid=6871;start=0#msg60796 date=1084961888]
[quote author=iago link=board=7;threadid=5407;start=0#msg60487 date=1084760373]
For some arithmatic:

This C code:
[code]int edx = 3;
edx = edx * 2 + 5;[/code]

will probably look like this:
[code]mov edx, 3
lea edx, [5 + edx*2]
[/code]

lea's can be used for arithmatic.
[/quote]

Note that that particular C-code probably would be optimized to assign a constant to edx ;)
[/quote]

Yes, but that would defeat the example :P
May 19, 2004, 12:09 PM

Search