ARM汇编:如何设置多个比较来执行一条指令?
ARM Assembly: How to set more than one comparing for executing a instruction?
我尝试在不使用跳转指令的情况下将此代码更改为 ARM:
if a == 0 || b == 1 then c:=10 else c:=20;
if d == 0 && e == 1 then f:=30 else c:=40;
我为第一个循环执行此操作。但我不确定。是真的吗?
CMP r0, #0 ; compare if a=0
CMP r1, #1 ; compare if b=0
MOVEQ r3, #10
MOVNE r3, #20
第二个怎么做?
if a == 0 || b == 1 then c:=10 else c:=20;
你想在这里做的是比较条件的一部分。如果该部分为真,则整个条件为真,因为只要 x
或 y
中至少有一个为真,x OR y
就为真。如果第一部分为假,则计算第二部分。这样就变成了:
CMP r0, #0 ; compare a with 0
CMPNE r1, #1 ; compare b with 1 if a!=0
MOVEQ r3, #10 ; a is 0, and/or b is 1 -> set c = 10
MOVNE r3, #20 ; a is not 0, and b is not 1 -> set c = 20
if d == 0 && e == 1 then f:=30 else c:=40;
此处您要计算条件的一部分,然后仅当第一部分为真时才计算第二部分。如果两部分都为真,则整个条件为真,否则为假:
CMP r0, #0 ; compare d with 0
CMPEQ r1, #1 ; compare e with 1 if d==0
MOVEQ r3, #30 ; d is 0, and e is 1 -> set f = 30
MOVNE r3, #40 ; d isn't 0, and/or e isn't 1 -> set f = 40
我尝试在不使用跳转指令的情况下将此代码更改为 ARM:
if a == 0 || b == 1 then c:=10 else c:=20;
if d == 0 && e == 1 then f:=30 else c:=40;
我为第一个循环执行此操作。但我不确定。是真的吗?
CMP r0, #0 ; compare if a=0
CMP r1, #1 ; compare if b=0
MOVEQ r3, #10
MOVNE r3, #20
第二个怎么做?
if a == 0 || b == 1 then c:=10 else c:=20;
你想在这里做的是比较条件的一部分。如果该部分为真,则整个条件为真,因为只要 x
或 y
中至少有一个为真,x OR y
就为真。如果第一部分为假,则计算第二部分。这样就变成了:
CMP r0, #0 ; compare a with 0
CMPNE r1, #1 ; compare b with 1 if a!=0
MOVEQ r3, #10 ; a is 0, and/or b is 1 -> set c = 10
MOVNE r3, #20 ; a is not 0, and b is not 1 -> set c = 20
if d == 0 && e == 1 then f:=30 else c:=40;
此处您要计算条件的一部分,然后仅当第一部分为真时才计算第二部分。如果两部分都为真,则整个条件为真,否则为假:
CMP r0, #0 ; compare d with 0
CMPEQ r1, #1 ; compare e with 1 if d==0
MOVEQ r3, #30 ; d is 0, and e is 1 -> set f = 30
MOVNE r3, #40 ; d isn't 0, and/or e isn't 1 -> set f = 40