flat assembler
Message board for the users of flat assembler.

Index > Main > optimization

Author
Thread Post new topic Reply to topic
FlashBurn



Joined: 06 Jan 2005
Posts: 87
FlashBurn 23 Jul 2005, 10:07
I like to know which code I should use!

Code:
mov esi,ADDR
mov eax,[esi+foo_t.data]
    


or

Code:
mov eax,[ADDR+foo_t.data]
    
Post 23 Jul 2005, 10:07
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 23 Jul 2005, 14:34
hi FlashBurn

use which better suite your code,

if you need to use esi then use it...

but notice the difference

Code:
mov esi,ADDR 
mov eax,[esi+foo_t.data] 
    


Code:
mov esi,[ADDR]
mov eax,[esi+foo_t.data] 
    


Code:
dec [ADDR]
mov esi,[ADDR]
inc esi
mov eax,[esi+foo_t.data] 
    


Code:
inc [ADDR]
mov esi,ADDR 
dec esi
mov eax,[esi+foo_t.data] 
    
Post 23 Jul 2005, 14:34
View user's profile Send private message Visit poster's website Reply with quote
El Tangas



Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
El Tangas 23 Jul 2005, 17:26
This kind of code, when you change a register just before using it as part of an adress, can generate a penalty called Address Generation Interlock (AGI), causing the processor to stall for 1 cycle.

Code:
mov esi,ADDR
mov eax,[esi+foo_t.data]
    


So, if you can choose, this is better.

Code:
mov eax,[ADDR+foo_t.data]
    
Post 23 Jul 2005, 17:26
View user's profile Send private message Reply with quote
james



Joined: 07 Sep 2005
Posts: 45
Location: Australia
james 08 Sep 2005, 09:10
But are they really equivilant ?
Post 08 Sep 2005, 09:10
View user's profile Send private message MSN Messenger Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 08 Sep 2005, 14:11
james,
they are fully exchangeable, the difference is :

this uses register (dynamic)

Code:
mov esi,ADDR 
mov eax,[esi+foo_t.data] 
    


this uses immediate value (fix)

Code:
mov eax,[ADDR+foo_t.data] 
    
Post 08 Sep 2005, 14:11
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 08 Sep 2005, 14:18
but first alter esi
Post 08 Sep 2005, 14:18
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 08 Sep 2005, 14:58
??? i don't understand, if ADDR is constant value (it has to be for "mov esi,ADDR" to work), and "foo_t.data" is constant value too, then "ADDR + foo_t.data" is also constant value, so you are asking on difference between
Code:
mov esi,const
mov eax,[esi + const]
    
and
Code:
mov eax,[const]
    

so difference is clear. sorry if i misunderstood something
Post 08 Sep 2005, 14:58
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav 08 Sep 2005, 16:04
for dynamic value:

Code:
lea esi,[stack_structure]
mov eax,[esi+stack_structure.somevalue]
    


for immediate value:

Code:
mov eax,[constant_structure.somevalue]
    


ps. they are totally different

_________________
[not enough memory]
Post 08 Sep 2005, 16:04
View user's profile Send private message Reply with quote
james



Joined: 07 Sep 2005
Posts: 45
Location: Australia
james 08 Sep 2005, 20:56
Hmmmn. I thought you had to dereference the addr first (ie: [ADDR])
then make an adjustment for the field you need.

Am I thinking that ADDR is a constant and not a pointer ?
Post 08 Sep 2005, 20:56
View user's profile Send private message MSN Messenger 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.