News:

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

Main Menu

Loop code macros, example and documentation.

Started by hutch--, September 04, 2016, 12:30:37 PM

Previous topic - Next topic

hutch--

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

jj2007

Is there any secret trick to get Vassily's macros perform a .Repeat .Until loop in MASM syntax? I've tried a lot but...
  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--

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)
*

jj2007

Yep, .break .if rdx{=97 looks a bit awkward but it works indeed.