Search code examples
inline-assemblymasm

Getting capital letters MASM x86


I am having some problems with getting the amount of uppercase letters in a string that will be passed in by a user. I have to write it in masm. My question is can i use an:

AND al, some bitstream
;TO DO LOGIC HERE

to get only capital letters? My code correctly gets the amount of lowercase letters, I just cant seem to figure out the capital letters. Also, this string has some random characters in it, such as: (<)>?$#@&. Is it as simple as that? or do I need a lot more logic to accomplish this?

Something like this?

jmp getNext         
getNext: mov al,[esi]
     cmp al,0
     je exitProc  ;exit loop
     cmp al,'a'
         jl noChange  ;increases my counters
         cmp al,'z'
         jle toUpperCase ;counts lowercase
         cmp AL,'A'  
         jl noChange 
         cmp AL,'Z' 
         jg noChange
         jl toCount  ;counts uppercase

I keep getting 0 as my answer and cannot figure out why. I am clearly very challenged by MASM.

It seems that my toCount never gets called. Instead the lines:

         cmp AL,'A'  
         jl noChange 
         cmp AL,'Z' 
         jl toCount  ;counts uppercase

Seem to only call noChange. Which is causing the value increased in toCount to never be called. I still cannot figure out what is wrong with this. It is the same exact thing as the test for the lowercase letter, except using the captial letters in the cmp.


Solution

  • What needs to be done is the following:

        cmp al,'A'  
        jl noChange ;inc counter
        cmp al,'Z' 
        jle toCount ;count uppercase
        cmp al,'a'
        jl noChange ;inc counter
        cmp al,'z'
        jle toUpperCase ;count lowercase
    

    In ASCII 'A' = 65 and 'Z' = 90. 'a' = 97 and 'z' = 122. My issue was that I was testing for the higher ASCII characters first, which would ignore any ASCII characters from 65-90 (A-Z).