Author Topic: Demo of a high level macro.  (Read 301 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5894
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Demo of a high level macro.
« 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
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 8822
  • Assembler is fun ;-)
    • MasmBasic
Re: Demo of a high level macro.
« Reply #1 on: July 27, 2018, 02:43:47 AM »
Code: [Select]
  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?

Code: [Select]
.Repeat
    conout str$(var),lf
    sub var, 1
.Until var<cnt

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5894
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Demo of a high level macro.
« Reply #2 on: July 27, 2018, 03:08:25 AM »
Doubt it, ML64 does not support .Repeat or .Until  .
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin: