News:

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

Main Menu

Nested .REPEAT, .IF and .WHILE ?

Started by Quan, June 20, 2025, 07:12:40 PM

Previous topic - Next topic

Quan

I have this simple programme here
include \masm32\include\masm32rt.inc

testing MACRO
xor eax, eax
mov esi, offset strHW
.REPEAT
inc eax
mov edi, offset strHW + 5
add esi, eax
xor ecx, ecx
add ecx, 11
cld
repe cmpsb
.IF !ZERO?
GOTO found
.ENDIF

.UNTIL eax == 10
:found
mov ebx, -1
ENDM

.data
data_start EQU $

strHW db 'Hello World!', 0
    strQuery db 'test32.exe', 0
   
.code
start:
testing

push 0
call ExitProcess
end start
and I'm getting this error here.
C:\3\test.asm(35) : fatal error A1010:unmatched block nesting : .if-.repeat-.while

I think my syntax is correct. Am I missing something? Or .if being nested in .repeat is not allowed?

EDIT: The condition in .UNTIL is supposed to be eax == 10 and not ecx == 10. The same error is still produced after this edit.

Quan

Adding to this, I'm essentially trying to replicate this chunk of code in a macro so I can use it multiple times.
xor eax, eax
mov esi, offset strHW
loop_start:
inc eax
mov edi, offset strHW + 5
add esi, eax
xor ecx, ecx
add ecx, 11
cld
repe cmpsb
jz found

cmp eax, 10
jne loop_start

found:
mov ebx, -1
Is anything I'm doing wrong or unconventional?

EDIT: Minor, unrelated logic error, cmp instruction at the end of the loop is supposed to compare eax with 10, not ecx with 10.

_japheth

Hi,

GOTO is an "assembly-time" jump, accepted inside macros only, and probably only useful if combined with conditional assembly instructions ( IF, ELSE [note the missing "dot"]).
That's supposedly not at all what you did want to do!? A simple JMP should work better.
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

Quan

Ahh, right, I didn't notice that, thanks!

Quote from: _japheth on June 21, 2025, 12:14:41 AMThat's supposedly not at all what you did want to do!? A simple JMP should work better.
I don't think this works? Because putting a label in a macro for the JMP instruction, and then using the macro multiple times causes the compiling to complain about label redefinition. Or is that okay and can safely be ignored?

_japheth

Quote from: Quan on June 22, 2025, 12:19:25 AMBecause putting a label in a macro for the JMP instruction, and then using the macro multiple times causes the compiling to complain about label redefinition. Or is that okay and can safely be ignored?

No, since this is an error and no warning. You have to use the LOCAL directive ( inside the macro and tightly following the MACRO directive) to declare your label inside the macro as "local".
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

mabdelouahab

.IF !ZERO?
                ;GOTO found
.ENDIF

NoCforMe

Quote from: mabdelouahab on June 22, 2025, 05:00:54 AM        .IF !ZERO?
                    ;GOTO found
        .ENDIF

??????
Looks like net effect is ... nothing.
32-bit code and Windows 7 foreva!

Quan

Yea, that doesn't work. I did find out about the .BREAK directive, but it doesn't really do the same thing.

Quote from: _japheth on June 22, 2025, 12:37:33 AMNo, since this is an error and no warning. You have to use the LOCAL directive ( inside the macro and tightly following the MACRO directive) to declare your label inside the macro as "local".
Got it, thanks  :thumbsup: I totally misunderstood the purpose of the LOCAL directive. I thought it was for declaring local variables and not labels. It's working now, thanks!