x86 汇编中凯撒密码的问题
我有以下说明作为凯撒密码程序的一部分。
overFlow:
sub bl, 1Ah
ret
underFlow:
add bl, 1Ah
ret
correctFlow:
cmp bl, 7Ah
jg overFlow
cmp bl, 61h
jl underFlow
ret
enc_byte:
add bl, encOffset
call correctFlow
ret
将 ASCII 小写字母放入 BL
中,并在调用 enc_byte 后,将字母移动 encOffset 个字母并纠正溢出。
但由于某种原因,正确流程中的比较无法正常工作。当 CorrectFlow中BL=8Dh
时,jg overFlow
指令不跳转,而是jl underFlow
指令在第二个cmp
。为什么会发生这种情况? 8Dh 明显大于 7Ah,那为什么它没有按预期跳跃呢?
我知道回报很奇怪。 overFlow 和 underFlow 标签是返回对 CorrectFlow 的调用的标签。这是故意的,据我所知,与该问题无关。
I have the following instructions as part of a Caesar cipher program.
overFlow:
sub bl, 1Ah
ret
underFlow:
add bl, 1Ah
ret
correctFlow:
cmp bl, 7Ah
jg overFlow
cmp bl, 61h
jl underFlow
ret
enc_byte:
add bl, encOffset
call correctFlow
ret
An ASCII lowercase letter is put into BL
and after enc_byte is called, it shifts the letter by encOffset letters and corrects for an overflow.
But for some reason the compare in correctFlow doesn't work correctly. When BL=8Dh
in correctFlow, the jg overFlow
instruction does not jump, and instead jl underFlow
jumps after the second cmp
. Why is this happening? 8Dh is clearly greater than 7Ah, so why doesn't it jump as expected?
I know the returns are weird. The overFlow and underFlow labels are the ones that return the call to correctFlow. This is intentional and as far as I know, doesn't have anything to do with the issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这种情况是因为
jg
和jl
将cmp
的结果视为两个操作数是有符号数字。7Ah
和8Dh
分别表示有符号数 +122 和 -115。显然,后者是最小的。您需要的是无符号比较。请改用指令
ja
和jb
。This happens because
jg
andjl
treat the outcome ofcmp
as if the two operands were signed numbers.7Ah
and8Dh
represent signed numbers +122 and -115, respectively. Obviously, the latter is the smallest.What you need is unsigned comparison. Use instructions
ja
andjb
instead.