flat assembler
Message board for the users of flat assembler.

Index > Main > lea with if statement?

Author
Thread Post new topic Reply to topic
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 18 Mar 2009, 03:59
Code:
cmp eax,ebx
mov  eax,ecx
jb   @f
dec       eax
sub      edx,eax
@@:    


What is the equivalent using an if statement? I can't figure it out. Embarassed


The closest I have come up with generates
Code:
cmp     eax,ebx
jb   @f
mov       eax,ecx
dec  eax
sub      edx,eax
jmp  blahblah
@@:
mov      eax,ecx
blahblah:    



Please help.. I think if statements could make my code more readable but I don't want it to be bloated..




P.S. these are just examples


Last edited by Azu on 18 Mar 2009, 04:46; edited 1 time in total
Post 18 Mar 2009, 03:59
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20448
Location: In your JS exploiting you and your system
revolution 18 Mar 2009, 04:41
mov eax,ecx also works, it also doesn't change any flags. Plus, t is one byte shorter and has better scheduling than lea
Post 18 Mar 2009, 04:41
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 18 Mar 2009, 04:46
Thanks, updated the example. Still have the same question, though. Any answers would be appreciated.
Post 18 Mar 2009, 04:46
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20448
Location: In your JS exploiting you and your system
revolution 18 Mar 2009, 04:49
Do you mean how to use the macro ".if"? Or the assembler "if"?

Basically the code you show above looks fine to me. jcc is really all that is available on x86 unless you want to delve into cmovcc.
Post 18 Mar 2009, 04:49
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 18 Mar 2009, 04:51
What I meant was;


Please post the code using if statements instead of cmp and jb, that generates the code in the first example. I can not figure it out.

For FASM, not jcc.
Post 18 Mar 2009, 04:51
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20448
Location: In your JS exploiting you and your system
revolution 18 Mar 2009, 04:55
Okay, so I think you want to use the ".if" macro set.
Code:
include "if.inc" ;comes with the windows package download
.if eax,b,ebx
  ;do something
.else
  ;do something else
.endif    
I think that is how they work. I've never used them before.
Post 18 Mar 2009, 04:55
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 18 Mar 2009, 05:00
Azu wrote:
What is the equivalent using an if statement? I can't figure it out. Embarassed


The closest I have come up with generates
Code:
cmp      eax,ebx
jb   @f
mov       eax,ecx
dec  eax
sub      edx,eax
jmp  blahblah
@@:
mov      eax,ecx
blahblah:    


Thought there was some kind of trick to it and I was just doing something wrong. Guess it's just impossible afterall?
Post 18 Mar 2009, 05:00
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20448
Location: In your JS exploiting you and your system
revolution 18 Mar 2009, 05:03
Well, I presume it works like this:
Code:
include "if.inc" ;comes with the windows package download
.if eax,nb,ebx
  mov     eax,ecx
  dec     eax
  sub     edx,eax
.else
  mov     eax,ecx
.endif    
Is that what you are asking?
Post 18 Mar 2009, 05:03
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: 20448
Location: In your JS exploiting you and your system
revolution 18 Mar 2009, 05:04
BTW: The .if macros just generate what you wrote in the first post. There is no magic, unfortunately.
Post 18 Mar 2009, 05:04
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 18 Mar 2009, 05:05
I was just wondering if code like
Code:
cmp     eax,ebx
mov     eax,ecx
jb      @f
dec     eax
sub     edx,eax
@@:    
can be generated with if statements (and if so how), or only bloated code like
Code:
cmp     eax,ebx
jb      @f
mov     eax,ecx
dec     eax
sub     edx,eax
jmp     blahblah
@@:
mov     eax,ecx
blahblah:    
Post 18 Mar 2009, 05:05
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20448
Location: In your JS exploiting you and your system
revolution 18 Mar 2009, 05:11
I see, I am not expert with these macro but as far as I can tell you will only get the bloated version.

I would suggest that if you are interested in making efficient code for things like the above that using .if/.else/.endif structures is not the best way. Manual coding is always going to give at least as good and sometimes better.
Post 18 Mar 2009, 05:11
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: 4624
Location: Argentina
LocoDelAssembly 18 Mar 2009, 06:20
Code:
cmp eax, ebx
mov eax, ecx

.if ~CARRY?
  dec eax
  sub edx, eax
.endif    


Question
Post 18 Mar 2009, 06:20
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 18 Mar 2009, 06:33
Thanks guys Smile
Post 18 Mar 2009, 06:33
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.