1
 cmp al,'0'
 je true
 cmp al,'1'
 je true
 cmp al,'2'
 je true
 cmp al,'3'
 je true
 cmp al,'4'
 je true
 cmp al,'5'
 je true
 cmp al,'6'
 je true
 cmp al,'7'
 je true
 cmp al,'8'
 je true
 cmp al,'9'
 je true
 jne error 

我很感兴趣如何使用数字的间隔和 ASCII 码来减少 cmp 的数量。谢谢。

4

1 回答 1

3

ASCII 码是数字。当您写入“0”时,汇编器将其转换为 30h = 48d。正如您在此 ASCII 表中看到的,字母“0”到“9”由连续数字 30h..39h 表示。所以你可以撤销你的检查:如果al低于 '0' 或al高于 '9',那么 goto error。你只需要两个比较:

cmp al,'0'
jb error      ; jump if below
cmp al,'9'
ja error      ; jump if above
true:
于 2015-11-09T12:29:08.063 回答