-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathhello_jump.asm
58 lines (47 loc) · 905 Bytes
/
hello_jump.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
bits 64
default rel
segment .data
switch:
dq main.case0
dq main.case1
dq main.case2
i: dq 2
a: dq 3
b: dq 5
segment .bss
temp resq 1
segment .text
global main
extern ExitProcess
main:
; This block basically implements:
; if (a < b) {
; temp = a;
; a = b;
; b = temp;
; }
mov rax, [a]
mov rbx, [b]
cmp rax, rbx
jge .end
mov [temp], rax
mov [a], rbx
mov [b], rax
; end block
; This is just demonstrating unconditional jump. Change ``i`` to jump differently.
; It's essentially a switch statement.
mov rax, [i] ; move value of i to rax
lea rcx, [switch]
jmp [rcx + rax * 8] ; switch (i)
.case0:
mov rbx, 100
jmp .end
.case1:
mov rbx, 101
jmp .end
.case2:
mov rbx, 103
jmp .end
.end:
xor eax, eax
call ExitProcess