Reputation: 18149
Suppose that you have a number stored in EAX
. How can I check whether this number represents an uppercase character or not?
Frankly, I haven't tried anything. The closest idea I had was to create an array of upper case characters ('A','B','C,'D',...) and then check if EAX
was equal to any of these. Is there a simpler way to do this in NASM Assembly?
I'm using 64-bit CentOS, for a 32-bit program.
Upvotes: 0
Views: 1778
Reputation: 58762
A somewhat simpler version of Michael's answer, assuming you can clobber al
:
sub al, 'A'
cmp al, 'Z' + 1 - 'A'
setc al ; al now contains 1 if al contained an uppercase letter, and 0 otherwise
If you want to branch, then replace the setc
with jc
or jnc
as appropriate.
Upvotes: 0
Reputation: 58467
For ASCII characters, something like this would work:
cmp eax,'A'
setnc bl ; bl = (eax >= 'A') ? 1 : 0
cmp eax,'Z'+1
setc bh ; bh = (eax <= 'Z') ? 1 : 0
and bl,bh ; bl = (eax >= 'A' && eax <= 'Z')
; bl now contains 1 if eax contains an uppercase letter, and 0 otherwise
Upvotes: 1
Reputation: 6454
If your character is encoded in ASCII then you could just check EAX
is in the range 65 to 90 ('A' to 'Z'). For other encodings (Unicode in primis, think about diacritics) I think the answer is not trivial at all and you should eventually use an API from the OS.
Upvotes: 3