flat assembler
Message board for the users of flat assembler.

Index > Main > lea esi,[esi+ecx*8]

Author
Thread Post new topic Reply to topic
eskizo



Joined: 22 Nov 2005
Posts: 59
eskizo
Hello all,

I would like to know if this expression is actually some kind of "macro" or it is a real machine instruction... I mean:

Code:
lea esi, [esi + ecx * 8]

;is compiled as follow?

push esi
push ecx
mul ecx, 8
add esi, ecx
lea esi, [esi]
pop ecx
pop esi
    
Post 28 Jun 2009, 22:53
View user's profile Send private message Reply with quote
arigity



Joined: 22 Dec 2008
Posts: 45
arigity
yes that is a legitimate use of the lea instruction and is not a macro, you should see the intel developers manuals for more information on questions like these.
Post 28 Jun 2009, 23:16
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
There is no multiplication involved with lea. It is shift left. That is, multiplication by power of 2.

2, 4, 8, 16, 32, 64, 128... and so on, are powers of 2. You can't use lea to multiply by some other value.

EDIT: what's the point of:
Code:
lea esi, [esi]    
??
Post 29 Jun 2009, 00:22
View user's profile Send private message Reply with quote
eskizo



Joined: 22 Nov 2005
Posts: 59
eskizo
thanks arigity & Borsuc.

Borsuc, forget my mistake.
Post 29 Jun 2009, 01:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
Also the push/pop of esi will nullify your result completely. The only change from the code you posted is that the flags are altered. In a real lea instruction no flage are altered. Maybe this?
Code:
pushfd
push ecx
mul ecx, 8
add esi, ecx
pop ecx
popfd    
Post 29 Jun 2009, 14:45
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
You mean "imul ecx,8", don't you? Wink
Post 29 Jun 2009, 14:52
View user's profile Send private message Visit poster's website Reply with quote
manfred



Joined: 28 Feb 2009
Posts: 43
Location: Racibórz, Poland
manfred
Actually "shl ecx, 3". Multiplication in addressing is left shift by scale field in opcode's SIB byte.

_________________
Sorry for my English...
Post 29 Jun 2009, 14:56
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
Code:
pushfd
rept 8 {add esi, ecx}
popfd    
Post 29 Jun 2009, 15:01
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
manfred wrote:
Actually "shl ecx, 3". Multiplication in addressing is left shift by scale field in opcode's SIB byte.

And why not "sal ecx,3"? Wink

revolution: good one. Smile But I'd prefer:
Code:
times 8: add esi,ecx    


Last edited by Tomasz Grysztar on 29 Jun 2009, 15:08; edited 1 time in total
Post 29 Jun 2009, 15:07
View user's profile Send private message Visit poster's website Reply with quote
manfred



Joined: 28 Feb 2009
Posts: 43
Location: Racibórz, Poland
manfred
revolution wrote:
Code:
pushfd
rept 8 {add esi, ecx}
popfd    
Not (AFAIK)
Code:
pushfd
times 8 dw 0CE01h
popfd    
? Wink
@up: Because SAL is same opcode as SHL.

_________________
Sorry for my English...
Post 29 Jun 2009, 15:07
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
Code:
pushfd
rept 2{rept 2\{rept 2\\{add esi,ecx\\}\}}
popfd    
Can't do that with times Wink
Post 30 Jun 2009, 00:56
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
No?
Code:
times 2 times 2 times 2 add esi, ecx    
Assembled as a 24 bytes binary by fasm 1.69.00
Post 30 Jun 2009, 01:16
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
Can it be mixed?
Code:
times 2 rept 4{add esi,ecx}    
Razz
Post 30 Jun 2009, 01:30
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
eskizo wrote:
thanks arigity & Borsuc.

Borsuc, forget my mistake.
no worries I just pointed out that you can't multiply by any value -- so if you run into a compile error, you should know. Saves time looking up or asking Wink

@revolution: times is assembly-time directive, rept is macroinstruction... rept will make multiple "add esi,ecx" during assembly stage as if you wrote them multiple times.
Post 30 Jun 2009, 02:23
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
manfred wrote:
Because SAL is same opcode as SHL.

It may be the same opcode, but you've got the assembly language so that you can verbalize you ideas better than just with opcodes.
Post 30 Jun 2009, 06:50
View user's profile Send private message Visit poster's website Reply with quote
manfred



Joined: 28 Feb 2009
Posts: 43
Location: Racibórz, Poland
manfred
revolution wrote:
Can it be mixed?
Maybe
Code:
rept 4 { times 2 add esi, ecx }    
Very Happy

_________________
Sorry for my English...
Post 30 Jun 2009, 13:43
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
manfred passes the test, well done.
Post 30 Jun 2009, 14:04
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
The reason it works is because at assembly time this is what fasm will see:

Code:
times 2 add esi, ecx
times 2 add esi, ecx
times 2 add esi, ecx
times 2 add esi, ecx    

_________________
Previously known as The_Grey_Beast
Post 30 Jun 2009, 15:31
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.