I wrote this macro while working on a project. Feel free to use and abuse it.
IsQuote checks a char supplied in a reg, or memory operand to see if it is a
double or single quote.
It uses the carry flag as a return.
carry set = quote
carry clear = no quote


IsQuote macro arg:req
   LOCAL ??YQ, ??IDONE
       cmp arg, 22h
       jz ??YQ
       
       cmp arg, 27h
       jz ??YQ
       
       clc
       jmp ??IDONE
   ??YQ:
       stc
   ??IDONE:
       
endm


Here is sample code to show its use. Compile as a console app.

include \masm32\include\masm32rt.inc

IsQuote macro arg:req
   LOCAL ??YQ, ??IDONE
       cmp arg, 22h
       jz ??YQ
       
       cmp arg, 27h
       jz ??YQ
       
       clc
       jmp ??IDONE
   ??YQ:
       stc
   ??IDONE:
       
endm

QuoteCheck PROTO :DWORD

.data?
   Char1    db ?
.data
   TestStr1 db 'This string is "just" for testing.',0
   TestStr2 db 'This string is ',27h,'just',27h,' for testing.',0
.code

Start:
ALIGN 4

   call main
   inkey
   exit

main proc
       cls
       print offset TestStr1,13,10
       print "Checking for double quotes....",13,10
       invoke QuoteCheck,addr TestStr1
       
       print offset TestStr2,13,10
       print "Checking for single quotes....",13,10
       invoke QuoteCheck,addr TestStr2
       
       mov Char1, '"'
       IsQuote Char1
       jnb @f
       print "char1 is a quote char", 13,10
   @@:
       ret

main endp

QuoteCheck proc pStr:dword
       push esi
       mov esi, pStr               ; edit--> fixed pointer
       xor ecx, ecx
   
   @@:
       mov al, BYTE PTR
       inc ecx
       or al, al                           ; check for end of string
       jz Done
       
       IsQuote al                          ; check if char is a quote char
       jnb @b                              ; if carry clear, not a quote
       
       push ecx
       print "the char is a quote", 13, 10
       pop ecx
       jmp @b
   Done:
       pop esi
   ret

QuoteCheck endp

end Start


I hope somebody finds it useful, besides me :D
Posted on 2009-07-19 08:09:17 by rags
Not what I need right now, but cool, I think someone will see value here?
Posted on 2009-07-19 11:35:25 by Homer
I'd prefer a branchless version with more "clear" checks - something like the following :)


IsQuote macro arg:req
clc
cmp arg, '"'
stc
cmp arg, "'"
stc
endm
Posted on 2009-07-19 11:50:56 by f0dder