News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Repeat a block of code

Started by Magnum, September 18, 2010, 04:21:31 AM

Previous topic - Next topic

Magnum

I would like to repeat these 2 sounds 25 times and then wait the 2 secs.

I tried plugging 25 into the ecx register and decrementing it, but got an endless loop.



invoke Beep, 1000, 55 ; Sound duration and the frequency in hertz
invoke Beep, 800, 55
   
invoke Sleep, 2000

Have a great day,
                         Andy

MichaelW

Since ECX is one of the three registers not preserved across function calls, to use it as a loop counter you would need to preserve it around the function calls:

    mov ecx, 25
  @@:
    push ecx
    invoke Beep, 1000, 55 ; Sound duration and the frequency in hertz
    invoke Beep, 800, 55   
    pop ecx
    dec ecx
    jnz @B
    invoke Sleep, 2000


Or if you don't mind simply repeating the statements 25 times each , you can save some typing effort with:

REPEAT 25
    invoke Beep, 1000, 55 ; Sound duration and the frequency in hertz
    invoke Beep, 800, 55
ENDM   
invoke Sleep, 2000
eschew obfuscation

Magnum

Have a great day,
                         Andy