flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > if macro changes

Author
Thread Post new topic Reply to topic
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 06 Oct 2006, 19:20
Does anyone know how to change the .if macros (specifically >, <, >=, <= symbols) to use JL, JG, JLE, JGE. I need these changes so the .if macros can handle negative numbers correctly, right now they don't.
thanks in advance,
MadMatt
Post 06 Oct 2006, 19:20
View user's profile Send private message Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier 06 Oct 2006, 22:07
madmatt,

You can use:

Code:
.if eax, l, 250
...
.endif    


where l is the equivalent of less than and is converted to jnl to skip over the code between the .if and the .endif

Then use a and b (for ja and jb) for unsigned comparisons and l and g (for jl and jg) for signed comparisons

This code:

Code:
include 'win32ax.inc'

start:

        mov     eax, 251
        .if  eax, a, 250
             invoke MessageBeep, 0
        .endif

        ret

.end start    


Gets assembled to:

Code:
00401000 > B8 FB000000      MOV EAX,0FB
00401005   3D FA000000      CMP EAX,0FA
0040100A   76 08            JBE SHORT TestIF.00401014
0040100C   6A 00            PUSH 0
0040100E   FF15 3C204000    CALL DWORD PTR DS:[<&USER32.MessageBeep>>; USER32.MessageBeep
00401014   C3               RETN    


Or use:

Code:
.if signed eax > 256
...
.endif    


hth,

farrier

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 06 Oct 2006, 22:07
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 06 Oct 2006, 22:55
hmmmm, looks like ".if signed eax > 256" is what I'm looking for, I'll give it a try.
many thanks, farrier
[EDIT]
It works, but how would I get it to default to signed comparisons? So I won't have to use the signed parameter
Post 06 Oct 2006, 22:55
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 06 Oct 2006, 23:51
Not sure but try this
Code:
; after including the "standard" macros

macro .if [args]
{
  .if signed args
}    
Post 06 Oct 2006, 23:51
View user's profile Send private message Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier 07 Oct 2006, 03:03
madmatt,

You could look at the:

Fasm\INCLUDE\MACRO\IF.inc

file, and see how the signed argument is used. You could "roll your own" IF.inc and change it so that you would have to use "unsigned" instead of signed to specify an unsigned comparison.

It feels wrong to me to change something like this, but that's just me. Something like what locodelassembly suggested would be better, where you would leave the "source" alone and add a macro in your own madmatt.inc file.

farrier

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 07 Oct 2006, 03:03
View user's profile Send private message Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body 07 Oct 2006, 11:12
to locodelassembly:

in your code you miss "common" directive.
Post 07 Oct 2006, 11:12
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 12 Oct 2006, 09:58
locodelassembly:
The macro doesn't work for this:
.if eax, e, WM_USER
Post 12 Oct 2006, 09:58
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 12 Oct 2006, 13:52
And doesn't works with things like ".if eax > ebx & ecx < edx" because the "ecx < edx" is a unsigned comparison. Sorry, I don't know how to do this without modifying if.inc
Post 12 Oct 2006, 13:52
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 14 Oct 2006, 07:42
I'll have another look at the macro and see what I can do. The macro is quite complex though (in my opinion).
Post 14 Oct 2006, 07:42
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.