汇编语言,如何判断一个字符是字母还是数字??
发布网友
发布时间:2022-05-06 22:28
我来回答
共4个回答
热心网友
时间:2023-09-27 07:50
用比较指令,看字符的ASCII码值是否大于等于‘0’(30H)且小于等于‘9’(39H),若是,则是数字。
对字母,判定方法类似。
若大于等于‘A'且小于等于'Z',则是大写字母。
若大于等于’a'且小于等于‘z',则是小写字母。
热心网友
时间:2023-09-27 07:50
CODE SEGMENT
ASSUME CS:CODE
BUF DB '1qaz2w,,,,,sx3eASBX7dc'
NUM EQU $-BUF
START:
PUSH CS
POP DS
PUSH CS
POP ES
MOV CX,NUM
LEA SI,BUF
CLD
@M0:
LODSB
CALL ISNUMBER
CMP AH,1
JNE @M1
CALL DISPNUM
JMP @MM
@M1:
CALL ISALPHA
CMP AH,1
JNE @M2
CALL DISPALPHA
JMP @MM
@M2:
MOV AH,2
MOV DL,32
INT 21H
@MM:
LOOP @M0
MOV AH,4CH
INT 21H
;======================================
ISNUMBER PROC NEAR
CMP AL,'0'
JB @NONUMBER
CMP AL,'9'
JA @NONUMBER
MOV AH,1
@NUMEXIT:
RET
@NONUMBER: MOV AH,0
JMP @NUMEXIT
ISNUMBER ENDP
;=========================================
ISALPHA PROC NEAR
CMP AL,'A'
JB @NOALPHA
CMP AL,'z'
JA @NOALPHA
CMP AL,'Z'
JBE @ALPHA
CMP AL,'a'
JAE @ALPHA
JMP @NOALPHA
@ALPHA:
MOV AH,1
@ALPHAEXIT:
RET
@NOALPHA:
MOV AH,0
JMP @ALPHAEXIT
ISALPHA ENDP
;==========================================
DISPNUM PROC NEAR
PUSH AX
PUSH DX
MOV AH,2
MOV DL,'N'
INT 21H
POP DX
POP AX
RET
DISPNUM ENDP
;==========================================
DISPALPHA PROC NEAR
PUSH AX
PUSH DX
MOV AH,2
MOV DL,'A'
INT 21H
POP DX
POP AX
RET
DISPALPHA ENDP
;========================================
CODE ENDS
END START
热心网友
时间:2023-09-27 07:51
通过ASCII的码值来判断
热心网友
时间:2023-09-27 07:51
判断ASCII码