Does someone have a fast lowercase to uppercase algorithm they wouldn't mind posting? I've been searching for one that will convert a string such as "c:\convert\me\to\uppercase".
Posted on 2003-04-05 08:06:17 by tremors
Look in masm32.lib source code.
Posted on 2003-04-05 08:39:53 by bazik
Or do something along the lines of:

mov esi,offset string
mov edi,esi

test al,al
je @done
cmp al,61
jl @F
cmp al,7a
ja @F
and al,4fh
jmp @loop:

That should do it. It can probably be optimized somewhat, since it handles the string in bytes.

;length of string in dwords in ecx

mov esi,offset string
mov edi,esi

mov edx,eax
and ebx,40404040h
shr ebx,1
xor ebx,0ffffffffh
and eax,ebx
dec ecx
jne @B

Haven't tried it, was just something I wondered about.

Posted on 2003-04-05 09:18:38 by Fake51
I haven't tried this but it should work:

mov esi, offset szString
or al,20h
sub al,20h
or al,al
jnz @b

best regards,

Posted on 2003-04-05 09:30:06 by czDrillard
To convert from lower case to upper case, you have to AND the lower case character (byte) with 5Fh.

You must check if the character is one of the lower case letters before the ANDing operation, otherwise all the ASCII numbers and many of the punctuation and extended characters will also get modified to some other character (for example, the "-" sign would get converted to a carriage return).

If you want to convert from upper case to lower case, you would OR the character byte with 20h (after checking if the character is one of the upper case letters).

If you want to invert upper and lower case letters, you would XOR the character byte with 20h (after checking if the character is one of the upper case or lower case letters).

Posted on 2003-04-05 09:46:11 by Raymond
Posted on 2003-04-05 10:12:28 by bazik

Fake51: your code doesn't work in all cases... It might destroy some non-alphabetic characters.
I tried to make a routine that ONLY affects the exact range of 'a'-'z', and leaves all other values untouched:

Yeah, hadn't tried the second one, just posted it as a possible optimization. Your solution looks interesting.

Posted on 2003-04-05 11:06:07 by Fake51