문제

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.

도움이 되었습니까?

해결책 2

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

다른 팁

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.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top