Author Topic: Making If/Elseif/Else statement with macros  (Read 6032 times)

Offline MIchael

  • Jr. Member
  • *
  • Posts: 10
Making If/Elseif/Else statement with macros
« on: May 24, 2018, 12:11:01 PM »
Hi to all! After a long search on the Internet I couldn't solve my problem. How to implement If/Elseif/Else statement with macros, just like this:
Code: [Select]
if al, equal, bl
    mov rcx, 128
elseif al, greater, bl
    mov rcx, 1
else
    mov rcx, 0
endif
« Last Edit: May 25, 2018, 07:43:23 AM by MIchael »

Offline avcaballero

  • Full Member
  • **
  • Posts: 132
  • Country: es
    • Abre los Ojos al Ensamblador
Re: If/Elseif/Else statement with macros
« Reply #1 on: May 24, 2018, 07:02:59 PM »
Maybe you may have a look to the nasmx package. The win32\Demo15 use it:
Code: [Select]
if eax,ABOVE,[argv(.h)]
fdivp st1,st0  ; w/h
fld st0
fmul qword [var(.right)]
fxch
fmul qword [var(.left)]
fstp qword [var(.left)]
fstp qword [var(.right)]
else
fdivrp st1,st0 ; h/w
fld st0
fmul qword [var(.top)]
fxch
fmul qword [var(.bottom)]
fstp qword [var(.bottom)]
fstp qword [var(.top)]
endif

Offline MIchael

  • Jr. Member
  • *
  • Posts: 10
Re: If/Elseif/Else statement with macros
« Reply #2 on: May 24, 2018, 10:11:50 PM »
Hi to all! After a long search on the Internet I couldn't solve my problem. How to implement If/Elseif/Else statement with macros, just like this:
Code: [Select]
if al, equal, bl
    mov rcx, 128
elseif al, greater, bl
    mov rcx, 1
else
    mov rcx, 0
endif
Just like this?

%define equal ne
%define n_equal e
; you can add more definitions there

%macro if 3
    %push if
    cmp %1, %3
    j%2 %$ifnot
%endmacro

%macro elseif 3
    %ifctx if
%$ifnot:
        cmp %1, %3
        j%2 %$ifnot
    %else
       %error "ELSIF directive must be within an 'if' block."
    %endif
%endmacro
   
%macro else 0
    %ifctx if
        %repl else
        jmp %$ifend
%$ifnot:
    %else
        %error "ELSE directive must be within an 'if' or 'elseif' block."
    %endif
%endmacro
   
%macro endif 0
    %ifctx if
%$ifnot:
        %pop
    %elifctx else
%$ifend:
        %pop
    %else
        %error "ENDIF directive must be within an 'if' block."
    %endif
%endmacro
« Last Edit: May 24, 2018, 10:20:19 PM by MIchael »