News:

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

Main Menu

Demo of a high level macro.

Started by hutch--, July 27, 2018, 01:52:18 AM

Previous topic - Next topic

hutch--

This macro was designed for working in higher level code where you mainly use memory operands for loop code comparisons. It always uses RAX for the comparison as this is safe in a context where high level procedures use RAX for their return value. This type of comparison can always be done manually but the macro is aimed at clear coding in a high level context. For those with a sense of humour, the format is not dissimilar to ancient COBOL but it reads OK and is easy enough to use.

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

    include \masm32\include64\masm64rt.inc

    .code

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

entry_point proc

    LOCAL var   :QWORD
    LOCAL cnt   :QWORD
    LOCAL lcn   :QWORD

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

    mov var, 10
    mov cnt, 0

  lbl0:
    conout str$(var),lf
    sub var, 1
    jump lbl0 while var gt cnt      ; evaluate from bottom of loop

    conout lf

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

    mov var, 10
    mov cnt, 0

  lbl1:
    jump lbl2 if var eq cnt         ; evaluate from top of loop
    conout str$(var),lf
    sub var, 1
    jmp lbl1
  lbl2:

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

    mov lcn, 10

  nested:
    mov var, 10
    mov cnt, 0

    lbl3:
      conout str$(var),lf
      sub var, 1
      jump lbl3 while var gt cnt

    sub lcn, 1
    jump nested if lcn ne cnt

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

    waitkey
    .exit

entry_point endp

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

    end

jj2007

  lbl0:
    conout str$(var),lf
    sub var, 1
    jump lbl0 while var gt cnt      ; evaluate from bottom of loop


So that is the equivalent to this one, I suppose?

.Repeat
    conout str$(var),lf
    sub var, 1
.Until var<cnt

hutch--

Doubt it, ML64 does not support .Repeat or .Until  .