简体   繁体   English

装配中的CMP和jmp变化

[英]CMP and jmp variations in assembly

 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 

I`m interested how to reduce this amount of cmp using interval and ASCII codes for numerals. 我很感兴趣如何使用间隔和ASCII码来减少这个数量的cmp。 Thanks. 谢谢。

ASCII codes are numbers. ASCII码是数字。 When you write '0', the assembler transforms it to 30h = 48d. 当你写'0'时,汇编程序将它转换为30h = 48d。 As you see in this ASCII table the letters '0' to '9' are represented by the consecutive numbers 30h..39h. 正如您在此ASCII表中看到的那样,字母“0”到“9”由连续数字30h..39h表示。 So you can reverse your check: If al is below '0' or al is above '9', then goto error . 所以,你可以扭转你的检查:如果al低于“0”或al大于“9”,然后转到error You need only two comparisons: 您只需要两个比较:

cmp al,'0'
jb error      ; jump if below
cmp al,'9'
ja error      ; jump if above
true:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM