forked from cirosantilli/x86-assembly-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jmp.asm
65 lines (46 loc) · 1.68 KB
/
jmp.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
; # JMP
; Unconditional branch
; The jmp address has the following forms. Quoting Intel manual:
; - Near jump - A jump to an instruction within the current code segment
; (the segment currently pointed to by the CS register),
; sometimes referred to as an intrasegment jump.
; - Short jump - A near jump where the jump range is limited to
; –128 to +127 from the current EIP value.
; - Far jump - A jump to an instruction located in a different segment
; than the current code segment but at the same privilege level,
; sometimes referred to as an intersegment jump.
; - Task switch - A jump to an instruction located in a different task.
; END QUOTE.
; Short jump example:
; https://github.com/cirosantilli/x86-bare-metal-examples/blob/6606a2647d44bc14e6fd695c0ea2b6b7a5f04ca3/reboot.S
; TODO:
; - only near jump and short jump are possible in userland.
; - NASM automatically decides between near and short, you cannot explicitly choose
; - task switch jump example
%include "lib/asm_io.inc"
ENTRY
; max +-128 bytes away
; short: displacement uses 1 byte only
jmp short jmp_short_label
ASSERT_FAIL
jmp_short_label:
; Segmentation fault?
;jmp word jmp_word_label
;jmp_word_label:
; near: 4 bytes displacement
jmp near jmp_label
ASSERT_FAIL
jmp_label:
; Allows to move outside code segment.
; Not allowed in ELF.
;jmp far jmp_far_label
;jmp_far_label:
mov eax, $ + 7
jmp eax
; jmp to the adress in eax
;mov eax, $ : 5 bytes
;jmp eax : 2 bytes
; Seg fault: stops in the middle of next instruction
;mov eax, $ + 8
;jmp eax
EXIT