News:

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

A macro for your use and abuse - IsQuote

Started by rags, July 19, 2009, 12:51:19 PM

Previous topic - Next topic

rags

I'm not too good at writing macros, but here is one I have written to check if a char in a reg or memory position is a single or double
quote.

It uses the carry flag as a return: Carry set if the char is a quote, clear if not.


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 showing it's 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, offset TestStr2
        xor ecx, ecx
   
    @@:
        mov al, BYTE PTR [esi+ecx]
        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

God made Man, but the monkey applied the glue -DEVO