forked from cirosantilli/x86-assembly-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jcc.asm
88 lines (57 loc) · 1.59 KB
/
jcc.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
; # Jcc
; # Conditiona jump
; Family of conditional jumps.
; Conditional branches of the form `jX` and `jnX` exist for all flags X.
; `jX` jumps when the corresponding flag is set. `jnX` jumps when clear.
%include "lib/asm_io.inc"
ENTRY
; # jz
; # jnz
; # je
; # jne
; je is the same as jz: http://stackoverflow.com/questions/14267081/difference-between-je-jne-and-jz-jnz
; jz is specially common with cmp, as `cmp` sets the `z` if the operands are equal.
; The C code:
;if (eax == ebx) assert_fail();
; Has equivalent:
mov eax, 0
mov ebx, 1
cmp eax, ebx
jnz jnz_test
ASSERT_FAIL
jnz_test:
; # jg
; # jl
; Large family of instructions that consider the ZF, CF, SF, OF and PF
; flags to do jumps.
; Those flags are set by `cmp`, so a `cmp; Jcc` is a common combo.
; Signed:
; - jg, jge, jl, jle
; - jng, jnge, jnl, jnle
; Unsigned verions:
; - ja, jae, jb, jbe
; - jna, jnae, jnb, jnbe
; mnemonics:
; - `g`: greater
; - `l`: less
; - `a`: above
; - `b`: below
mov eax, 0
cmp eax, 1
ASSERT_FLAG jl
ASSERT_FLAG jle
mov eax, 1
cmp eax, 0
ASSERT_FLAG jg
ASSERT_FLAG jge
mov eax, 0
cmp eax, 0
ASSERT_FLAG jle
ASSERT_FLAG jge
; # jc
; CF.
stc
ASSERT_FLAG jc
clc
ASSERT_FLAG jnc
EXIT