News:

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

Question about .IF .ENDIF

Started by Tight_Coder_Ex, December 03, 2009, 03:32:16 AM

Previous topic - Next topic

Tight_Coder_Ex

Is it possible to use .IF to test the contion of a flag

As an example

    bt    eax, 8

.if  CF
    ; my code if bit 8 is on
.endif

thomas_remkus

I don't think you can do that. You might need to do a "test" then "jmp".

sinsi

.IF (CARRY?)
Also ZERO? OVERFLOW? SIGN? and PARITY? Not sure if the brackets are required.
Light travels faster than sound, that's why some people seem bright until you hear them.

jj2007

Quote from: sinsi on December 03, 2009, 04:31:37 AM
.IF (CARRY?)
Also ZERO? OVERFLOW? SIGN? and PARITY? Not sure if the brackets are required.

Not required. I use .If Zero? etc all the time.

Be very careful with constructs like .If eax && Zero?  because the flag you are testing might be gone when you arrive at "Zero?". Check with Olly what goes and what not.

dedndave

Quote.If eax && Zero?
wouldn't that be the case where you would use parens ?
i.e.
.If (eax && Zero?)
doesn't that cause it to completely evaluate the expression before testing ?

Ficko

Quote from: dedndave on December 03, 2009, 01:01:41 PM
.If (eax && Zero?)
doesn't that cause it to completely evaluate the expression before testing ?

Looks like not:

.if (eax && CARRY?)
.endif
;OR EAX,EAX
;JE SHORT
;JNB SHORT
.if (CARRY? && eax)
.endif
;JNB SHORT
;OR EAX,EAX
;JE SHORT
.if (CARRY? && ZERO?)
.endif
;JNB SHORT
;JNE SHORT


Just wondering do someone has macros for
.if (CARRY? || ZERO?)  etc. structures to emit "jbe" "jae" etc. ?
::)

Tight_Coder_Ex

Thank-you, works as expected and brackets are not required in version 6.14

jj2007

Just for fun.

Quoteinclude \masm32\include\masm32rt.inc

.code
start:

   xor edx, edx
   mov eax, 123
   sub edx, 1            ; dec edx does not change the carry flag!
   .if eax && Carry?
      MsgBox 0, "Would love to see that", "Hi", MB_OK
   .else
      MsgBox 0, "Failed miserably, sorry", "Hi", MB_OK
   .endif

   xor edx, edx
   mov eax, 123
   sub edx, 1
   .if Carry? && eax
      MsgBox 0, "Would love to see that", "Hi", MB_OK
   .else
      MsgBox 0, "Failed miserably, sorry", "Hi", MB_OK
   .endif

   exit
end
start