News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Example of .IF macro in loop design.

Started by hutch--, August 10, 2018, 05:43:03 PM

Previous topic - Next topic

hutch--

While both the .repeat - .until macro and the .while - .endw macro work correctly, they both must use a register where the .IF macro will accept 2 memory operands which is often simpler in higher level code. For the price of nominating a normal label, the .IF macro is simpler to use and more flexible in how you can use it. Examples below.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    USING r12
    LOCAL var1  :QWORD
    LOCAL var2  :QWORD

    SaveRegs

  ; -------------------------------------

    mov var1, 1
    mov var2, 5

  lbl1:
    conout str$(var1),lf
    add var1, 1
    .IF var1 le var2 goto lbl1          ; eval last

    conout lf

  ; -------------------------------------

    mov var1, 1
    mov var2, 5

  lbl2:
    .IF var1 gt var2 goto lbl3          ; eval first
    conout str$(var1),lf
    add var1, 1
    jmp lbl2
  lbl3:

    conout lf

  ; -------------------------------------

    mov var1, 1
    mov var2, 5

    jmp lbl5                            ; eval first by jmp to .IF
  lbl4:
    conout str$(var1),lf
    add var1, 1
  lbl5:
    .IF var1 le var2 goto lbl4          ; eval at end

  ; -------------------------------------

    waitkey
    RestoreRegs
    .exit

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end