; nested if-then-else statements
bits 16

; ifstm <instruction>
%macro ifstm 1+
  %push if
  %1
%endmacro

; then_ <cond>
%macro then_ 1
  %ifctx if
    j%-1 %$neq
  %else
    %error "If-then-else syntax error"
  %endif
%endmacro

; else_
%macro else_ 0
 %ifctx if
   jmp %$end
   %$neq:
 %endif
%endmacro

; ifend
%macro ifend 0
  %ifctx if
    %$end:
    %pop
  %endif
%endmacro



ifstm cmp ax,5
then_ e
  mov bx,5
  ifstm cmp cx,2    ; corrected!
  then_ ne
    add bx,2
  else_
  ifend
else_
  mov bx,9
  int 0x12
ifend

