;Author Privalov
;I have made some macros than can do it for you,
;they can be nested up to 10 times, but it's quite simple to change it to
;a bit higher value. The macros for your use are:
;.if, .else, .elseif, .endif - the .if and .elseif need three arguments,
;first should be register/memory, second the condition (e, ne, a, b, ae, be)
; and third the register/memory/value, for example:

; .if eax,e,8
; when eax=8
; .elseif eax,ae,10h
; when eax>=10h
; .else
; other cases
; .endif

;below this line hll_if.inc begins:
;---------------------------------------------

macro _jifnot v1,c,v2,label
{
cmp v1,v2
if c eq ne
je label
else
jn#c label
end if
}

macro .if v1,c,v2
{
_IFST = _IFST shl 1
local _endif
_9ENDIF equ _8ENDIF
_8ENDIF equ _7ENDIF
_7ENDIF equ _6ENDIF
_6ENDIF equ _5ENDIF
_5ENDIF equ _4ENDIF
_4ENDIF equ _3ENDIF
_3ENDIF equ _2ENDIF
_2ENDIF equ _1ENDIF
_1ENDIF equ _0ENDIF
_0ENDIF equ _endif
local _else
_9ELSE equ _8ELSE
_8ELSE equ _7ELSE
_7ELSE equ _6ELSE
_6ELSE equ _5ELSE
_5ELSE equ _4ELSE
_4ELSE equ _3ELSE
_3ELSE equ _2ELSE
_2ELSE equ _1ELSE
_1ELSE equ _0ELSE
_0ELSE equ _else
_jifnot v1,c,v2,_else
}

macro .else
{
jmp _0ENDIF
_0ELSE:
_IFST = _IFST or 1
}

macro .elseif v1,c,v2
{
local _else_new
jmp _0ENDIF
_0ELSE:
_IFST = _IFST or 1
_0ELSE equ _else_new
_jifnot v1,c,v2,_else_new
}

macro .endif
{
if _IFST and 1 = 0
_0ELSE:
end if
_0ENDIF:
_0ELSE equ _1ELSE
_1ELSE equ _2ELSE
_2ELSE equ _3ELSE
_3ELSE equ _4ELSE
_4ELSE equ _5ELSE
_5ELSE equ _6ELSE
_6ELSE equ _7ELSE
_7ELSE equ _8ELSE
_8ELSE equ _9ELSE
_0ENDIF equ _1ENDIF
_1ENDIF equ _2ENDIF
_2ENDIF equ _3ENDIF
_3ENDIF equ _4ENDIF
_4ENDIF equ _5ENDIF
_5ENDIF equ _6ENDIF
_6ENDIF equ _7ENDIF
_7ENDIF equ _8ENDIF
_8ENDIF equ _9ENDIF
_IFST = _IFST shr 1
}

_IFST = 0

Gges :alright:




Posted on 2002-07-23 02:17:32 by Asmgges
Here is the improved version of hll_if.inc file, it needs fasm 1.40 because it uses some of its small new features. Altough it's not yet released, you can get 1.40 beta here.




macro .if v1,c,v2
{
__IF equ
local _endif
__ENDIF equ _endif
local _else
__ELSE equ _else
cmp v1,v2
jn#c __ELSE
}

macro .else
{
jmp __ENDIF
__ELSE:
restore __IF
__IF equ ,
}

macro .elseif v1,c,v2
{
local _else_new
jmp __ENDIF
__ELSE:
restore __ELSE
__ELSE equ _else_new
cmp v1,v2
jn#c __ELSE
restore __IF
__IF equ ,
}

macro .endif
{
if __IF eq
__ELSE:
end if
__ENDIF:
restore __ELSE
restore __ENDIF
restore __IF
}

jnne equ je
jnna equ ja
jnnb equ jb
Posted on 2002-07-23 10:20:04 by Tomasz Grysztar
Thank you Tomasz :)
These macro simplify me largely programming and I take a big pleasure to use Fasm
Friendly... Gges
Posted on 2002-07-23 11:38:22 by Asmgges
Hi !:)
Fasm1_40 and old macro .if endif OK
Fasm1_40 and macro news .if endif ERROR MESSAGE
It would seem that macro news .if.endif do not support to be in a loop
For example

jnz .b1
error:invalid value



p_proj1vais:
.if dword[tm],e,1 ; si tir = 1
; -------------------------------------
; Teste si un projectile est disponible
; -------------------------------------
mov ebx,proj1 ; pointeur ebx sur projectile1
mov ecx,6 ; boucle pour 6 projectiles
.b1:
.if dword[ebx],e,0 ; si cpt_sp = 0
mov dword[ebx],1 ; cpt_sp
mov eax,[x_vais] ; x_souris
add eax,70 ; +70
mov [ebx+4],eax ; x_souris+70 dans x_sp
mov eax,[y_vais] ; y_souris
add eax,20 ; +20
mov [ebx+8],eax ; y_souris+20 dans y_sp
mov dword[ebx+12],8 ; valeur du deplacementx_sp
stdcall [PlaySound],szSound3,NULL,SND_FILENAME+SND_ASYNC
mov ecx,1
.else
add ebx,44 ; passe au sprite suivant
.endif
dec ecx ; decremente la boucle
jnz .b1
mov dword[tm],0
.endif
ret

Friendly......Gges
Posted on 2002-07-24 07:03:01 by Asmgges
Just replace the "_endif" with "..endif" etc. everywhere, so local labels won't be affected.
Posted on 2002-07-24 07:17:20 by Tomasz Grysztar
For the loop OK compilation OK run OK

New problem this time with .elseif (also with old .elseif)

.elseif dword,e,2
error:invalid value.


.if dword[numtab],e,1
; Evolution des attaquants
; ------------------------
; CPT0 | Xd | Yd | Sp | Src Sp | Trajet | Vit | Proj
evolspg 100, 800, 0, gat1, src_gat1, trg1g_1, 100
evolspg 300, 800, 200, gat2, src_gat1, tr1g_2, 100
evolspex 100, 800, 300, at1, src_vais1, tr2g_8, 100, rock1
evolspex 200, 800, 100, at2, src_vais2, tr1g_1, 20, rock2
Here 30 appeals to the same procedure (who calls the others of it)
.........

.elseif dword[numtab],e,2
evolspg 100, 800, 0, gat1, src_gat2, trg1g_1, 100
evolspg 300, 800, 200, gat2, src_gat1, tr1g_2, 100
evolspex 100, 800, 300, at1, src_vais1, tr2g_4, 100, rock1
evolspex 200, 800, 100, at2, src_vais2, tr1g_2, 20, rock2
Here 30 appeals to the same procedure (who calls the others of it)
.........

.endif

Here macro modified


macro .if v1,c,v2
{
__IF equ
local ..endif
__ENDIF equ ..endif
local ..else
__ELSE equ ..else
cmp v1,v2
jn#c __ELSE
}

macro .else
{
jmp __ENDIF
__ELSE:
restore __IF
__IF equ ,
}

macro .elseif v1,c,v2
{
local ..else_new
jmp __ENDIF
__ELSE:
restore __ELSE
__ELSE equ ..else_new
cmp v1,v2
jn#c __ELSE
restore __IF
__IF equ ,
}

macro .endif
{
if __IF eq
__ELSE:
end if
__ENDIF:
restore __ELSE
restore __ENDIF
restore __IF
}

jnne equ je
jnna equ ja
jnnb equ jb

Gges
Posted on 2002-07-24 08:13:28 by Asmgges
The last line of .elseif macro should be corrected from "__IF equ ," to "__IF equ" (just remove the comma).
Posted on 2002-07-24 08:36:57 by Tomasz Grysztar
I am going to try
I have to cut Direct Draw does not love connection Internet at the same time as the execution of the programs.........:tongue:
Gges
Posted on 2002-07-24 08:44:16 by Asmgges
Everything is OK!!:alright:
Which fast repairs!:eek:
Tomasz you are a very big artist of the assembler.:tongue:
Thanks :) .......Gges
Posted on 2002-07-24 08:56:58 by Asmgges
I encourage the users of Fasm to use these macro, they a lot simplify programming especially in second reading and modification of the code source
I put back below the version of the macro tested this day.


;author Privalov
;.if, .else, .elseif, .endif - the .if and .elseif need three arguments,
;first should be register/memory, second the condition (e, ne, a, b, ae, be)
; and third the register/memory/value, for example:

; .if eax,e,8
; when eax=8
; .elseif eax,ae,10h
; when eax>=10h
; .else
; other cases
; .endif

macro .if v1,c,v2
{
__IF equ
local ..endif
__ENDIF equ ..endif
local ..else
__ELSE equ ..else
cmp v1,v2
jn#c __ELSE
}

macro .else
{
jmp __ENDIF
__ELSE:
restore __IF
__IF equ ,
}

macro .elseif v1,c,v2
{
local ..else_new
jmp __ENDIF
__ELSE:
restore __ELSE
__ELSE equ ..else_new
cmp v1,v2
jn#c __ELSE
restore __IF
__IF equ
}

Good programming in all
Friendly.....Gges
Posted on 2002-07-24 09:16:35 by Asmgges
And still this to be right !!!:grin:


macro .endif
{
if __IF eq
__ELSE:
end if
__ENDIF:
restore __ELSE
restore __ENDIF
restore __IF
}

jnne equ je
jnna equ ja
jnnb equ jb


Gges :tongue:
Posted on 2002-07-24 09:25:32 by Asmgges
Also even more simplified variant should work correctly:


macro .elseif v1,c,v2
{
local ..else_new
jmp __ENDIF
__ELSE:
restore __ELSE
__ELSE equ ..else_new
cmp v1,v2
jn#c __ELSE
}
Posted on 2002-07-24 09:50:48 by Tomasz Grysztar
Yes no problem.:)
It works very well also!:alright:
Friendly... Gges
Posted on 2002-07-24 10:16:59 by Asmgges
Privalov, nacz czhelowek. :grin:
EAST POWER!
Posted on 2002-07-24 13:36:08 by comrade
Da, no Polsha eto zapadnyi vostok.
Posted on 2002-07-24 13:44:21 by Tomasz Grysztar
They are new instructions for Fasm?:(
They are the new MMMMMMXXXX??:confused:
It is necessary to read them from right to left??:o
If it is the new syntax of the assembler then I return to program in BASIC!!!!!:grin:
Sorry:stupid:
Friendly.. Gges:)
Posted on 2002-07-24 13:58:43 by Asmgges
:grin:
Posted on 2002-07-24 14:07:38 by Tomasz Grysztar
Eschyo po-russki govorish?!
Posted on 2002-07-24 14:28:26 by comrade
Hi, I'm using FASM 1.45 and I'm trying to use the follow code


.if eax,e,0
; whoops, no object passed in
invoke SetLastError, ERROR_INVALID_PARAMETER
mov eax, 0
ret
.endif

When I try to compile this I get following error "jne ..else?00000439"

Can you or some one tell me how can I use the .if macro, I don't need to use .else

Thanks for your help.

Sincerely,
Alonso
Posted on 2003-02-17 20:02:40 by alonso