如何用汇编语言编写下面的if else语句?
C代码:
If ( input < WaterLevel)
{
MC = 1;
}
else if ( input == WaterLevel)
{
MC = 0;
}伪码
If input < Water Level
Send 1 to microcontroller
Turn Motor On
Else if input == Water Level
Send 0 to microcontroller
Turn Motor Off组件不完整:(MC-微控制器)
CMP Input, WaterLevel
MOV word[MC], 1
MOV word[MC], 2发布于 2016-11-15 12:34:21
如果我们想用C语言做一些事情,比如:
if (ax < bx)
{
X = -1;
}
else
{
X = 1;
}它在Assembly中的外观如下所示:
cmp ax, bx
jl Less
mov word [X], 1
jmp Both
Less:
mov word [X], -1
Both:发布于 2016-11-15 12:31:03
由于不知道您正在使用的特定汇编语言,我将用伪代码编写以下代码:
compare input to waterlevel
if less, jump to A
if equal, jump to B
jump to C
A:
send 1 to microcontroller
turn motor on
jump to C
B:
send 0 to microcontroller
turn motor off
C:
...对于前三个命令:大多数汇编语言都有条件分支命令来测试0或符号位的值,并根据位是否被设置来跳转。
https://stackoverflow.com/questions/40602029
复制相似问题