The MASM Forum

Microsoft 64 bit MASM => Examples => Topic started by: hutch-- on July 27, 2018, 01:52:18 AM

Title: Demo of a high level macro.
Post by: hutch-- on July 27, 2018, 01:52:18 AM
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
Title: Re: Demo of a high level macro.
Post by: jj2007 on July 27, 2018, 02:43:47 AM
  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
Title: Re: Demo of a high level macro.
Post by: hutch-- on July 27, 2018, 03:08:25 AM
Doubt it, ML64 does not support .Repeat or .Until  .