WCU / Cybersecurity
~/CSC 471/Class 02/KP 11
Class 02 · KP 11 / 23

Arithmetic

add  rax, rbx       ; rax = rax + rbx
sub  rax, 4         ; rax = rax - 4
inc  rcx            ; rcx = rcx + 1
imul rax, rbx       ; signed multiply
imul eax, ecx, 10   ; eax = ecx * 10

; multiply-by-constant tricks (faster than imul):
shl  rax, 3         ; rax = rax * 8   (shift left by 3)
lea  rax, [rax+rax*2]  ; rax = rax * 3
  • Arithmetic updates RFLAGS (ZF, SF, CF, OF).
  • Compilers replace * power-of-two with shl and small constants with lea chains.