con*_*non 1 x86 assembly ascii
所以,我有一段代码设置边界来检查字符是否是字母(不是数字,不是符号),但我认为它不适用于大写和小写之间的字符。你能帮我吗?谢谢!
mov al, byte ptr[esi + ecx]; move the first character to al
cmp al, 0 ; compare al with null which is the end of string
je done ; if yes, jump to done
cmp al, 0x41 ; compare al with "A" (upper bounder)
jl next_char ; jump to next character if less
cmp al, 0x7A ; compare al with "z" (lower bounder)
jg next_char ; jump to next character if greater
//do something if it's a letter
next_char:
//do something different
Run Code Online (Sandbox Code Playgroud)
你可以或 0x20 给每个字符;这将使大写字母小写(并用其他非字母字符替换非字母字符):
...
je done ; This is your existing code
or al, 0x20 ; <-- This line is new!
cmp al, 0x41 ; This is your existing code again
...
Run Code Online (Sandbox Code Playgroud)
注意:如果您的代码应该使用 0x7F 以上的字母(如“Ä”、“Ó”、“Ñ”),它会变得非常复杂。这种情况下的一个问题是这些字符的 ASCII 代码在 Windows 控制台程序(例如:“Ä”= 0x8E)和 Windows GUI 程序(“Ä”= 0xC4)中是不同的,在其他操作系统中甚至可能不同。 ..