在ARM体系中,所有ARM指令均可条件执行,设置了一些条件执行码,但这些条件码对应设置CPSR中的Z, C, N, V标志位:
l           0000 = EQ - Z set (equal)
l           0001 = NE - Z clear (not equal)
l           0010 = CS - C set (unsigned higher or same)
l           0011 = CC - C clear (unsigned lower)
l           0100 = MI - N set (negative)
l           0101 = PL - N clear (positive or zero)
l           0110 = VS - V set (overflow)
l           0111 = VC - V clear (no overflow)
l           1000 = HI - C set and Z clear (unsigned higher)
l           1001 = LS - C clear or Z set (unsigned lower or same)
l           1010 = GE - N set and V set, or N clear and V clear (greater or equal)
l           1011 = LT - N set and V clear, or N clear and V set (less than)
l           1100 = GT - Z clear, and either N set and V set, or N clear and V clear (greater than)
l           1101 = LE - Z set, or N set and V clear, or N clear and V set (less than or equal)
l           1110 = AL - always
l           1111 = NV - never
怎样去理解这些设置呢?拿1001 = LS - C clear or Z set (unsigned lower or same)来说:
是为什么LS就对应 C clear and Z set。看下面的例子:
MOV R0, #5
MOV R1, #6
CMP R0, R1
MOVLS R2, R0 ; if R0 < R1 则 将小值存入R2中
在这个例子中,MOVLS 能够正确执行的条件C=0 and z=1 成立,是通过CMP设置了

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/shansan/archive/2008/10/24/3137216.aspx

 

if(a>b) a++;
else b++;
对应的ARM指令如下:R0 等于a, R1等于b
CMP R0, R1         ;R0与R1比较
ADDHI R0, R0, #01   ;大于执行R0+=1;
ADDLS R1, R1, #01  
 
If(a != 10 && b != 20) a=a+b;
对应的ARM指令如下:
CMP R0, #10       ;R0与10比较
CMPNE R1, #20    ;不相等执行R1与20比较
ADDNE R0, R0, R1 ;不相等执行R0=R0+R1