News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

loop code example

Started by stevenxie, November 04, 2020, 02:18:06 AM

Previous topic - Next topic

stevenxie

hi,the following is a loop_code example.In this example, will show you. do and. loop, . rept and. endr, . repeat and. until, . while and. endw, IF/..1 WHILE, Advanced syntax simulation techniques for scanf and printf macros.

example one:
; *******************************************************

    include \masm32\include64\masm64rt.inc

    .data
   a dq ?
   b dq ?
   s dq ?
.code

; ******************************************************

entry_point proc
       
    printf("\t please input a and b \t")
    scanf("%ld%ld", offset a, offset b)
    mov rax,a
    add rax,b
    mov s,rax
    printf("\t a+b=%ld",s)
    printf("\n")
    waitkey

    .exit

entry_point endp

;*******************************************************

    end



example two:

; ******************************************************************

    include \masm32\include64\masm64rt.inc

    .code

;******************************************************************

entry_point proc
;-------------------------------------------------------------------

    USING rax
;-------------------------------------------------------------------
   
    LOCAL var1 :QWORD
    LOCAL var2 :QWORD
    LOCAL var3 :QWORD
    LOCAL var4 :QWORD
    var5 equ <32>
;-------------------------------------------------------------------
    conout "hello word",lf
    waitkey "Press any key to see the new .do .loop technique"
; ------------------------------------------------------------------

    mov var1, 60
    mov var2, 66

    .do
      conout str$(var1),";"
      add var1, 1
    .loop  IF var1 le var2 
;-------------------------------------------------------------------
    conout lf
    waitkey "Press any key to see the new .rept .endr technique"
;-------------------------------------------------------------------
    mov var1, 60
    mov var2, 66

    .rept IF var2 GE var1
        conout str$(var2),";"
        sub var2, 1
    .endr
;---------------------------------------------------------------------------   
    conout lf
    waitkey "Press any key to see the new .repeat .until technique"
;---------------------------------------------------------------------------
    mov var1, 60
    mov var2, 66

    .repeat
        conout str$(var2),";"
        sub var2, 1
    .until  var2{=0
;---------------------------------------------------------------------------

    conout lf
    waitkey "Press any key to see the new sigleline .IF/.WHILE technique"
;--------------------------------------------------------------------------
    mov var1, 60
    mov var2, 66

    lb_10:
        conout str$(var1),";"
        add var1, 1
    .WHILE var1 LE var2 goto_back_to lb_10
;--------------------------------------------------------------------------

    conout lf
    waitkey "Press any key to see the new jump technique"
; -------------------------------------------------------------------------

    mov var1, 60
    mov var2, 66

    lb_11:
      conout str$(var1),";"
      add var1, 1
    jump lb_11 WHILE var1 LE var2
; -------------------------------------------------------------------------

    conout lf
    waitkey "Press any key to see the new sigleline .while/.endw technique"

; --------------------------------------------------------------------------
   mov var2, 10
   mov rax,1
   mov var1,rax

    .while   ( (var2{0) || (var2}0) )
     
      conout str$(var2),";"
      sub var2,1   
     
    .endw     

;---------------------------------------------------------------------------
    conout lf
   waitkey
;---------------------------------------------------------------------------
    .if ((var1}=1) || (var2{1))
      printf("%d",80*50)
      printf("\t%d",50*60)
    .endif
;---------------------------------------------------------------------------

    conout lf
    waitkey
;---------------------------------------------------------------------------
    invoke ExitProcess,0
    ret
;---------------------------------------------------------------------------

entry_point endp

;***************************************************************************

    end











stevenxie

 Masm64 is as powerful as masm32, and masm64 advanced syntax simulation technology allows it to be used to develop large applications. I love masm64!

stevenxie

Hi,hutch, you must teach me MASM64, I strive to be your good student

Vortex

Hello stevenxie,

There are nice tutorials on the net. You can also study the examples and help files created by Hutch.

stevenxie

The above example has shown  MASM64 powerful development capabilities for anyone who laughs at MASM64, and the underlying foundation of the entire Microsoft development capability is based on incomparably powerful MASM64. MASM64 is the real driver of application development. Hutch, I will always support you and MASM! forever.