flat assembler
Message board for the users of flat assembler.

Index > Main > How is expressions like arr+eax*4 translated by fasm?

Author
Thread Post new topic Reply to topic
Bob++



Joined: 12 Feb 2013
Posts: 92
Bob++
If I have an expression such as

Code:
mov ebp,[arr+eax*4]
    


How is this [arr+eax*4] translated by fasm? a "mul" instruction is generated to get computed address or something like this?

Thanks in advance.
Post 16 Mar 2013, 17:14
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
The processor has actually support for such addressing: http://en.wikipedia.org/wiki/X86#Addressing_modes

Note however that fasm may sometimes perform some algebraic manipulation to either make your expression fit into one of the addressing modes (like transforming eax*5 to eax+eax*4), or re-order the terms to use a shorter addressing mode.
Post 16 Mar 2013, 19:15
View user's profile Send private message Reply with quote
Bob++



Joined: 12 Feb 2013
Posts: 92
Bob++
LocoDelAssembly, thanks very much. Smile
Post 16 Mar 2013, 19:30
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1408
Location: Toronto, Canada
AsmGuru62
Bob++

Always look into debugger for generated code:
That is what OllyDbg gives ('arr' is located at address 401120):
Code:
004024A0:      8B2C85 20114000      MOV     EBP, [EAX*4+401120]
    
Post 17 Mar 2013, 15:41
View user's profile Send private message Send e-mail Reply with quote
nmaps



Joined: 26 Oct 2012
Posts: 8
nmaps
Yeah, check out the sib byte addressing in x86.

You can do complex this like ebp+reg+reg*base2 or ebp+reg*base2+imm32
Post 22 May 2013, 06:33
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.