Author Topic: Loop code macros, example and documentation.  (Read 974 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4872
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Loop code macros, example and documentation.
« on: September 04, 2016, 12:30:37 PM »
Attached in the zip file is the latest macros64.inc file that has added a number of loop code macros. There is a HTM file that explains what they do and how they work (Documentation !!!!) and a working example of the 3 high level styles of loop code. This is the basic code in the demo.

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

    include \masm32\include64\masm64rt.inc

    .code

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

entry_point proc

    LOCAL var1 :QWORD
    LOCAL var2 :QWORD
    LOCAL var3 :QWORD
    LOCAL var4 :QWORD

    waitkey "Press any key to see the new .do .loop technique"

    mov var1, 10
    mov var2, 50

  ; ---------------------------------
    .do
      conout str$(var1),lf
      add var1, 1
    .loop WHILE var1 LT var2
  ; ---------------------------------

    waitkey "Press any key to see the new .rept .endr technique"

    mov var1, 10
    mov var2, 50

  ; ---------------------------------
    .rept IF var1 LT var2
      conout str$(var1),lf
      add var1, 1
    .endr
  ; ---------------------------------

    waitkey "Press any key to see the new jump technique"

    mov var1, 10
    mov var2, 50

  ; ---------------------------------
    lbl0:
      conout str$(var1),lf
      add var1, 1
      jump lbl0 WHILE var1 LT var2
  ; ---------------------------------

    waitkey

    invoke ExitProcess,0

    ret

entry_point endp

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

    end
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 7633
  • Assembler is fun ;-)
    • MasmBasic
Re: Loop code macros, example and documentation.
« Reply #1 on: September 08, 2016, 09:41:38 PM »
Is there any secret trick to get Vassily's macros perform a .Repeat .Until loop in MASM syntax? I've tried a lot but...
Code: [Select]
  mov rdx, 100
  if 0
.repeat
dec rdx
.until rdx==0 ; OK, works
  elseif 0
.repeat
dec rdx
.break .if sign? ; chokes
.break .if Sign? ; chokes
.break .if SIGN? ; OK
.break .if rdx==98 ; OK
.break .if rdx<=97 ; Bad conditional operator
.break .if rdx<96 ; error A2006:undefined symbol : rdx96
.until rdx ; OK, works
  elseif 0
.repeat
dec rdx
.until rdx>=0 ; forced error: Bad conditional operator
  elseif 0
.repeat
dec rdx
.until rdx>0 ; error A2008:syntax error : >
  elseif 1
.repeat
dec rdx
.until rdx gt 0 ; error A2095:constant or relocatable label expected
  endif

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4872
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Loop code macros, example and documentation.
« Reply #2 on: September 09, 2016, 01:28:42 AM »
The only problem I can see is the use of < or > which ML64 excludes. Vasily's macros use { and } instead. This data is at the beginning of his macro file.

comment * Comparison run-time operators

     Operator      Meaning
 
     ==            Equal
     {}            Not equal
     }             Greater than
     }=            Greater than or equal to
     {             Less than
     {=            Less than or equal to
     &             Bit test (format: expression & bitnumber)
     ~             Logical NOT
     |            Bit test
     &&            Logical AND

     ||            Logical OR
 
     CARRY?        Carry bit set
     OVERFLOW?     Overflow bit set
     PARITY?       Parity bit set
     SIGN?         Sign bit set
     ZERO?         Zero bit set
     CARRY?|ZERO?   ìåíüíå èëè ðàâíî
     ~(CARRY?|ZERO?)   áîëüøå
     äëÿ ñðàâíåíèÿ ÷èñåë ñî çíàêîì
     ~ZERO?&(SIGN?==OVERFLOW?)   áîëüøå(greate than)
     SIGN?==OVERFLOW?      áîëüøå èëè ðàâíî(greate than or equal)
     SIGN?{}OVERFLOW?      ìåíüøå(less than)
     ZERO?|(SIGN?{}OVERFLOW?)      ìåíüøå èëè ðàâíî(less than or equal)
*
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 7633
  • Assembler is fun ;-)
    • MasmBasic
Re: Loop code macros, example and documentation.
« Reply #3 on: September 09, 2016, 03:05:11 AM »
Yep, .break .if rdx{=97 looks a bit awkward but it works indeed.