尝试将 if 语句转换为程序集
我做错了什么?
这是我写的汇编:
char encode(char plain){
__asm{
mov al, plain
;check for y or z status
cmp al, 'y'
je YorZ
cmp al, 'z'
je YorZ
cmp al, 'Y'
je YorZ
cmp al, 'Z'
je YorZ
;check to make sure it is in the alphabet now
mov cl, al
sub cl, 'A'
cmp cl, 24
jl Other
sub cl, '6' ;there are six characters between 'Z' and 'a'
cmp cl, 24
jl Other
jmp done ;means it is not in the alphabet
YorZ:
sub al, 24
jmp done
Other:
add al, 2
jmp done
done:
leave
ret
}
}
这是它应该替换的 C 代码,但
char encode(char plain){
char code;
if((plain>='a' && plain<='x') || (plain>='A' && plain <='X')){
code = plain+2;
}else if(plain == 'y' || plain=='z' || plain=='Y' || plain == 'y'){
code = plain - 24;
}else{
code = plain;
}
return code;
}
它似乎将不是 y,z,Y,Z 的每个字符转换为等价的加 2,而不仅仅是A-Xa-x。有什么想法吗?
What am I doing wrong?
This is the assmebly I've written:
char encode(char plain){
__asm{
mov al, plain
;check for y or z status
cmp al, 'y'
je YorZ
cmp al, 'z'
je YorZ
cmp al, 'Y'
je YorZ
cmp al, 'Z'
je YorZ
;check to make sure it is in the alphabet now
mov cl, al
sub cl, 'A'
cmp cl, 24
jl Other
sub cl, '6' ;there are six characters between 'Z' and 'a'
cmp cl, 24
jl Other
jmp done ;means it is not in the alphabet
YorZ:
sub al, 24
jmp done
Other:
add al, 2
jmp done
done:
leave
ret
}
}
and this is the C code it's supposed to replace, but doesn't
char encode(char plain){
char code;
if((plain>='a' && plain<='x') || (plain>='A' && plain <='X')){
code = plain+2;
}else if(plain == 'y' || plain=='z' || plain=='Y' || plain == 'y'){
code = plain - 24;
}else{
code = plain;
}
return code;
}
It seems to convert every character that isn't an y,z,Y,Z into a plus 2 equivalent instead of just A-Xa-x. Any ideas why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
jl
是有符号比较。jl
is a signed comparison.我认为应该
是
相反的,你说有“6”-> 0x36-> “Z”和“a”之间有 54 个字符。
I think that
should be
otherwise, you are stating that there are '6' -> 0x36 -> 54 characters between 'Z' and 'a'.
对于无符号比较,您需要“jb”而不是“jl”。
For an unsigned comparison, you need 'jb' instead of 'jl'.