我正在处理的一个简单程序(用于作业)要求我将键击作为输入并返回它所属的类别(它是可打印的字符,十进制等)。在NASM中,我想根据其ASCII值比较输入击键
我正在使用cmp比较击键与最大值和/或最小值的类别(例如,如果击键的ASCII码高于0x7F,那么它是一个可打印的字符)
但是,显然有一些东西在我的比较中不起作用,因为无论如何,即当我使用退出按钮作为输入时,它不打印“控制键”。
难道是密钥需要一些更多的处理之前,他们可以根据ASCII值进行比较?
这里是我的代码
segment .data
controlKey: db "Control Key", 10
controlLen: equ $-controlKey
printableKey: db "Printable", 10
printableLen: equ $-printableKey
decimalKey: db "Decimal", 10
decimalLen: equ $-decimalKey
segment .bss
key resb 2
segment .text
global main
main:
mov eax, 3 ; system call 3 to get input
mov ebx, 0 ; standart input device
mov ecx, key ; pointer to id
mov edx, 2 ; take in this many bytes
int 0x80
control: ; check if it's a control key
mov ebx, 31 ; highest control key
mov edx, key
cmp edx, ebx
jg printable
mov eax, 4
mov ebx, 1
mov ecx, controlKey
mov edx, controlLen
int 0x80
; jmp exit ; It's obviously not any of the other categories
printable: ; Tell that it's a printable symbol
mov eax, 4
mov ebx, 1
mov ecx, printableKey
mov edx, printableLen
int 0x80
decimal:
mov ebx, 30h ; smallest decimal ASCII
mov edx, key
cmp edx, ebx
jl uppercase
mov ebx, 39h ; test against 9
cmp edx, ebx
jg uppercase
mov eax, 4
mov ebx, 1
mov ecx, decimalKey
mov edx, decimalLen
int 0x80
uppercase:
lowercase:
mov eax, 4 ; system call 4 for output
mov ebx, 1 ; standard output device
mov ecx, key ; move the content into ecx
mov edx, 1 ; tell edx how many bytes
int 0x80 ;
exit:
mov eax, 1
xor ebx, ebx
int 0x80
当我在程序运行时按下逃脱按钮时,它确实会读取它,但我已确认 – CodyBugstein 2013-02-28 23:11:45
奇怪,我无法重现该行为。 – 2013-02-28 23:12:52
运行该程序,并在输入提示符下按下转义键,您将得到一个像^这样的字符[ – CodyBugstein 2013-02-28 23:23:01