【问题标题】:How to write If only statement in assembly? [closed]如何在汇编中编写 If only 语句? [关闭]
【发布时间】:2016-11-15 09:14:09
【问题描述】:

如何在汇编中编写以下代码?

if(Input<WaterLevel)
{
     MC = 1;
}

我知道如何执行 if else 语句,但如果没有 else 语句怎么办。

【问题讨论】:

  • 它会做出同样的反应,如果它是真的它会进入,否则它会忽略它
  • 你只是把 else 部分去掉,就像在任何其他语言中一样?另外请不要标记不相关的语言。还有很多不同的汇编语言,答案不止一种。
  • 你测试条件,如果测试失败则跳过那个块
  • 你试过调试吗?它将完全按照您在问题中所写的方式工作,您不需要else
  • 真的很想将其作为your question about if-else from 5 hours ago 的副本关闭。这只是您已经得到答案的问题的一个子集,这不是很明显吗?你不明白这些答案吗?

标签: assembly


【解决方案1】:

您使用条件跳转,该跳转仅在条件为假时执行。 示例(伪代码):

        ...
        CMP $Input, $WaterLevel   ; compare variables
        JGE Continue              ; if $Input >= $WaterLevel, jump to "Continue"
        MOV $MC, 1                ; set $MC value
     Continue:
        ...

编辑:正如 Thilo 指出的那样,您需要使用与您的条件相反的条件进行条件跳转。

【讨论】:

  • 请注意,您必须反转条件:不是“如果为真,则执行块”,而是“如果为假,则跳开”。
【解决方案2】:

在 cmp 完成之后不要放任何东西。

来自https://www.tutorialspoint.com/assembly_programming/assembly_conditions.htm

CMP DX, 00  ; Compare the DX value with zero
JE  L7      ; If yes, then jump to label L7
.           ; Continue as normal. No else.
.
L7: ...

【讨论】:

    猜你喜欢
    • 2014-10-21
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 2016-06-28
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多