【问题标题】:Biconditional While Loop in x86 Assemblyx86 汇编中的双条件 While 循环
【发布时间】:2013-07-25 23:51:02
【问题描述】:

假设我有一个高级语言的 while 循环,看起来像:

当 i >= 0 且 x

x86 中的汇编代码看起来如何?我曾尝试考虑将 cmp 用于 while 语句的条件部分,但我不确定 AND 将如何实现。

谢谢

【问题讨论】:

    标签: loops assembly while-loop x86 conditional


    【解决方案1】:
        ;; assuming eax contains i, ecx contains x
    myloop:
        test eax, eax
        jl   exitloop  ; i < 0
        cmp  ecx, 5
        jge  exitloop  ; x >= 5
        ;; loop content goes here
        jmp myloop
    exitloop:
        ;; life continues after the loop
    

    【讨论】:

    • 因此,如果它是一个 AND 语句,那么这并不重要,因为如果任一语句为假,它就会退出循环,如果它是 OR 而不是 AND 怎么办?会有什么不同?
    • 您可以将 jl 更改为 jge,并将其目标地址更改为紧随第二个 jge 之后的标签。
    猜你喜欢
    • 1970-01-01
    • 2017-11-30
    • 2017-01-23
    • 2015-02-13
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    相关资源
    最近更新 更多