ARM base instruction -- ccmp (immediate)

Conditional Compare (immediate) sets the value of the condition flags to the result of the comparison of a register value and an immediate value if the condition is TRUE, and an immediate value otherwise.

此指令一般出现在 cmp 指令之后,表示双重比较。

条件比较(立即数)将条件标志的值设置为寄存器值和立即数(如果条件为真)的比较结果,否则把条件标志设置为#<nzcv>的值。

<nzcv> = 1 1 1 1

n = 0x8

z = 0x4

c = 0x2

v = 0x1

32-bit variant

Applies when sf == 0.

CCMP <Wn>, #<imm>, #<nzcv>, <cond>

64-bit variant

Applies when sf == 1.

CCMP <Xn>, #<imm>, #<nzcv>, <cond>

Decode for all variants of this encoding

integer n = UInt(Rn);

integer datasize = if sf == '1' then 64 else 32;

bits(4) flags = nzcv;

bits(datasize) imm = ZeroExtend(imm5, datasize);

bits(N) ZeroExtend(bits(M) x, integer N)

assert N >= M;

return Zeros(N-M) : x;

bits(N) Zeros(integer N)

return Replicate('0',N);

bits(N) Replicate(bits(M) x)

assert N MOD M == 0;

return Replicate(x, N DIV M);

Operation

bits(datasize) operand1 = X[n];

bits(datasize) operand2;

if ConditionHolds(cond) then

operand2 = NOT(imm);

(-, flags) = AddWithCarry(operand1, operand2, '1');

PSTATE.<N,Z,C,V> = flags;

(bits(N), bits(4)) AddWithCarry(bits(N) x, bits(N) y, bit carry_in)

integer unsigned_sum = UInt(x) + UInt(y) + UInt(carry_in);

integer signed_sum = SInt(x) + SInt(y) + UInt(carry_in);

bits(N) result = unsigned_sum<N-1:0>; // same value as signed_sum<N-1:0>

bit n = result<N-1>;

bit z = if IsZero(result) then '1' else '0';

bit c = if UInt(result) == unsigned_sum then '0' else '1';

bit v = if SInt(result) == signed_sum then '0' else '1';

return (result, n:z:c:v);

ccmp x19, #0x0, #0x4, ne # 判断 x19 是否等于 0 ,如果不等于(ne)零,z标志位为0;如果等于(eq)零,把标志位设置0x4。

4034f4: f9405a94 ldr x20, [x20, #176] // x20=walk_b->children

4034f8: f9405a73 ldr x19, [x19, #176] // x19=walk_a->children

4034fc: f100029f cmp x20, #0x0 // x20=walk_b ? 0

403500: fa401a64 ccmp x19, #0x0, #0x4, ne // x19=walk_a, 如果x19=0,ccmp会设置标志位0x4, b.eq将会跳转

403504: 54000140 b.eq 40352c <ferror@plt+0x164c> // b.none

for (walk_a = a->children, walk_b = b->children; walk_a && walk_b;

walk_a = walk_a->next, walk_b = walk_b->next) {

#<nzcv>:

ARM Process state -- CPSR

ARM Process state -- PSTATE

ARM base instruction -- ccmp (register)

相关推荐
Ronin-Lotus12 天前
微处理器原理与应用篇---ARM常见汇编指令
汇编·arm开发·微处理原理与应用
永夜的黎明15 天前
【二进制安全作业】250616课上作业1-栈溢出漏洞利用
c语言·汇编·安全
Geometry Fu17 天前
物联网控制技术 知识点总结 第三章 汇编语言 第四章 C51语言
汇编·物联网·51单片机
半桔17 天前
【Linux手册】进程的状态:从创建到消亡的“生命百态”
linux·运维·服务器·汇编·深度学习·面试
一条叫做nemo的鱼20 天前
从汇编的角度揭开C++ this指针的神秘面纱(下)
java·汇编·c++·函数调用·参数传递
一条叫做nemo的鱼21 天前
从汇编的角度揭开C++ this指针的神秘面纱(上)
汇编·c++·算法·函数调用·this指针·参数传递
qwertyuiop_i23 天前
汇编(函数调用)
汇编·windows·函数调用
不忘不弃23 天前
由汇编代码确定switch语句
汇编
南玖yy23 天前
深入理解 x86 汇编中的符号扩展指令:从 CBW 到 CDQ 的全解析
开发语言·汇编·arm开发·后端·架构·策略模式
iCxhust23 天前
汇编字符串比较函数
c语言·开发语言·汇编·单片机·嵌入式硬件