x86 汇编中凯撒密码的问题

发布于 2025-01-13 14:33:31 字数 675 浏览 3 评论 0原文

我有以下说明作为凯撒密码程序的一部分。

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 个字母并纠正溢出。

但由于某种原因,正确流程中的比较无法正常工作。当 CorrectFlowBL=8Dh时,jg overFlow指令不跳转,而是jl underFlow指令在第二个cmp。为什么会发生这种情况? 8Dh 明显大于 7Ah,那为什么它没有按预期跳跃呢?

我知道回报很奇怪。 overFlowunderFlow 标签是返回对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风轻花落早 2025-01-20 14:33:31

发生这种情况是因为 jgjlcmp 的结果视为两个操作数是有符号数字。

7Ah8Dh 分别表示有符号数 +122 和 -115。显然,后者是最小的。

您需要的是无符号比较。请改用指令 jajb

This happens because jg and jl treat the outcome of cmp as if the two operands were signed numbers.

7Ah and 8Dh represent signed numbers +122 and -115, respectively. Obviously, the latter is the smallest.

What you need is unsigned comparison. Use instructions ja and jb instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文