#Why this matters
Understanding registers and calling conventions lets you spot function inputs, yet most security logic lives inside branches and loops. Password checkers, protocol parsers, and obfuscation routines all reduce to comparisons, flags, and jumps.
When you open a binary in objdump or Ghidra, recognising these control-flow idioms turns hundreds of assembly lines into readable if statements and for loops across both x86-64 and ARM64 targets.
#Moving, calculating, and syntax conventions
Before tracing branches, check which syntax your tool displays. Ghidra and objdump -M intel use Intel syntax (mnemonic destination, source), whereas objdump -d without -M intel defaults to AT&T syntax (mnemonic source, destination with % before registers and $ before constants):
- Intel:
mov eax, 0x10copies0x10intoeax. - AT&T:
mov $0x10, %eaxdoes the exact same thing.
Core arithmetic and bitwise operations (add, sub, imul, and, or, xor, shl, shr) appear constantly. Two idioms deserve special attention:
xor eax, eaxzeroeseax(and upper bits ofrax) using fewer instruction bytes thanmov eax, 0.xor al, keyencodes or decodes a byte reversibly, because(b ^ key) ^ key == b.
ARM64 (AArch64) uses a load-store architecture. Instructions such as add, sub, and eor (exclusive OR) only touch registers; reading or writing memory requires ldr (load register) and str (store register), for example ldr w1, [x0, #4] to read 32 bits from x0 + 4 and str w1, [x0, #4] to write w1 to x0 + 4.
#Flags and conditional branching
Processors decide branches in two steps: an instruction updates status flags (RFLAGS on x86-64, NZCV on ARM64), and a branch instruction reads those flags.
On x86-64, cmp a, b computes a - b without storing the result, while test a, b computes a & b without storing it. Compilers routinely emit test rax, rax followed by jz (jump if zero) to check for NULL pointers or zero return values.
| Condition | x86-64 jump | ARM64 branch | Meaning |
|---|---|---|---|
| Equal / Zero | je / jz |
b.eq |
ZF == 1 (a == b) |
| Not equal | jne / jnz |
b.ne |
ZF == 0 (a != b) |
| Signed greater | jg |
b.gt |
Signed a > b |
| Signed less | jl |
b.lt |
Signed a < b |
| Unsigned above | ja |
b.hi |
Unsigned a > b |
| Unsigned below | jb |
b.lo |
Unsigned a < b |
ARM64 also provides cbz x0, label (compare and branch on zero) and cbnz x0, label, combining a zero check and branch into one instruction.
#Recognising loops and XOR decoders
Compilers often transform a for loop into a bottom-tested structure: check once before entering (or jump straight to the condition at the bottom), run the body, increment the counter, and jump backward if more iterations remain.
- Initmov ecx, 0 (counter = 0)
- Bodymovzx eax, byte [rdi+rcx]; xor al, 0x55
- Checkcmp al, byte [rsi+rcx]; jne fail
- Nextinc rcx; cmp rcx, 5; jb Body
When you see a backward jump (jb, jl, jne, or ARM64 b.lt) targeting an earlier address in the same function, you are looking at a loop. In Ghidra's Function Graph view, backward edges appear clearly as arrows looping upward around a block.
$ objdump -d -M intel ./xor_check | sed -n '/<verify_key>:/,/<main>:/p'
0000000000001160 <verify_key>:
1160: 31 c9 xor ecx,ecx
1162: 0f b6 04 0f movzx eax,BYTE PTR [rdi+rcx*1]
1166: 34 55 xor al,0x55
1168: 3a 04 0e cmp al,BYTE PTR [rsi+rcx*1]
116b: 75 0d jne 117a <verify_key+0x1a>
116d: 48 ff c1 inc rcx
1170: 48 83 f9 05 cmp rcx,0x5
1174: 75 ec jne 1162 <verify_key+0x2>
1176: b8 01 00 00 00 mov eax,0x1
117b: c3 ret
117a: 31 c0 xor eax,eax
117c: c3 retHere rdi holds the user buffer, rsi holds the 5-byte expected array, ecx starts at 0, every input byte is XORed with 0x55, and any mismatch exits immediately via jne 117a returning 0.
#Common mistakes
- Misreading AT&T operand order. In default
objdump -d,sub $0x20, %rspsubtracts0x20fromrsp, not the reverse. Pass-M intelwhen you prefer Intel order. - Confusing signed and unsigned jumps.
jl/jginterpret values as signed two's complement (0xffffffffis-1, which is< 100), whereasjb/jatreat them as unsigned (4294967295 > 100). - Assuming
testwrites its result. Bothcmpandtestonly update CPU flags; neither modifies its operands. - Reversing ARM64
strdirection.str x1, [x0]storesx1into memory atx0, unlikeldr x1, [x0]which loads from memory intox1.
#Summary
Control flow in compiled binaries relies on instructions that set flags (cmp, test, subs) paired with conditional branches (je, jne, jg, jb, b.eq, cbz). Loops stand out through counter updates and backward jumps to earlier addresses, and byte-level XOR loops can be reversed directly by applying the same XOR key to the target bytes. Checking operand syntax and signedness prevents common misreadings when analysing unfamiliar x86-64 or ARM64 functions.