C to assembly / C
1
C to assembly / C 1 last time AT&T syntax destination last - - PowerPoint PPT Presentation
C to assembly / C 1 last time AT&T syntax destination last jmp * lea condition codes ZF, SF, CF, OF set by last arithmetic instruction ZF = result was zero SF = result was negative (sign bit set) CF = overfmow if treating
1
2
3
4
4
5
6
6
7
8
9
9
10
10
10
11
12
13
14
15
15
15
16
16
17
int main() { const char *hello = "Hello World!"; ... } 0x4005C0
hello (on stack/register)
…'H''e''l''l''o''''W''o''r''l''d''!''\0'…
read-only data 18
…'H''e''l''l''o'' ''W''o''r''l''d''!''\0'…
read-only data
hello + 0 0x4005C0 hello + 5 0x4005C5 *(hello + 0) is 'H' *(hello + 5) is ' ' hello[0] is 'H' hello[5] is ' '
19
…'H''e''l''l''o'' ''W''o''r''l''d''!''\0'…
read-only data
hello + 0 0x4005C0 hello + 5 0x4005C5 *(hello + 0) is 'H' *(hello + 5) is ' ' hello[0] is 'H' hello[5] is ' '
19
…'H''e''l''l''o'' ''W''o''r''l''d''!''\0'…
read-only data
hello + 0 0x4005C0 hello + 5 0x4005C5 *(hello + 0) is 'H' *(hello + 5) is ' ' hello[0] is 'H' hello[5] is ' '
19
20
1
2
3
4
5
6
7
8
21
1
2
3
4
5
6
7
8
21
1
2
3
4
5
6
7
8
22
1
2
3
4
5
6
7
8
22
better style: *pointer = 'z'; better style: foo[1] = 'a';
1
2
3
4
5
6
7
8
'f''o''o''\0'
foo (on stack)
pointer foo + 1 == &foo[0] + 1
23
better style: *pointer = 'z'; better style: foo[1] = 'a';
1
2
3
4
5
6
7
8
'f''o''o''\0'
foo (on stack)
pointer foo + 1 == &foo[0] + 1
23
better style: *pointer = 'z'; better style: foo[1] = 'a';
1
2
3
4
5
6
7
8
'b''o''o''\0'
foo (on stack)
pointer foo + 1 == &foo[0] + 1
23
better style: *pointer = 'z'; better style: foo[1] = 'a';
1
2
3
4
5
6
7
8
'b''o''o''\0'
foo (on stack)
pointer foo + 1 == &foo[0] + 1
23
better style: *pointer = 'z'; better style: foo[1] = 'a';
1
2
3
4
5
6
7
8
'b''o''z''\0'
foo (on stack)
pointer foo + 1 == &foo[0] + 1
23
better style: *pointer = 'z'; better style: foo[1] = 'a';
1
2
3
4
5
6
7
8
'b''a''z''\0'
foo (on stack)
pointer foo + 1 == &foo[0] + 1
23
24
✭✭✭✭✭✭✭✭✭✭✭✭✭✭ ✭ ❤❤❤❤❤❤❤❤❤❤❤❤❤❤ ❤
24
25
25
25
26
27
28
29
30
31
cr4bd@power1 : /if22/cr4bd ; man stdio … STDIO(3) Linux Programmer's Manual STDIO(3) NAME stdio - standard input/output library functions SYNOPSIS #include <stdio.h> FILE *stdin; FILE *stdout; FILE *stderr; DESCRIPTION The standard I/O library provides a simple and efficient buffered stream I/O interface. Input and output is mapped into logical data streams and the physical I/O characteristics are concealed. The functions and macros are listed below; more information is available from the individual man pages.
32
STDIO(3) Linux Programmer's Manual STDIO(3) NAME stdio - standard input/output library functions … List of functions Function Description
check and reset stream status fclose close a stream … printf formatted output conversion …
33
1
2
3
4
5
6
7
8
34
1
2
3
4
5
6
7
8
34
1
2
3
4
5
6
7
8
34
35
35
36
36
37
38
38
39
39
39
40
41
42
43
43
43
unsigned long long unsigned int int 44
45
45
45
45
46
46
46
47
48
49
50
51
52
52
53
54
54
54
55
55
55
56
57
57
x × 2−y 58
59
−231
+230
+229
+22
+21
+20
0111 1111… 1111 1000 0000… 0000 1111 1111… 1111
60
−231
+230
+229
+22
+21
+20
−1 1 231 − 1 −231 −231 + 1
0111 1111… 1111 1000 0000… 0000 1111 1111… 1111
60
−231
+230
+229
+22
+21
+20
−1 1 231 − 1 −231 −231 + 1
0111 1111… 1111 1000 0000… 0000 1111 1111… 1111
60
61
61
62
62
62
63
64
65
66
67
67
68
69
69
70
71
72
73
73
74
75
76
77
78
79
80
signed conditional jumps: JL, JLE, JG, JGE, … e.g. JL (jump if less) checks SF + OF
unsigned conditional jumps: JA, JAE, JB, JBE, … e.g. JB (jump if below) checks CF
81
82
82
83
84
✘ ❳❳❳❳ ❳
85
✘ ❳❳❳❳ ❳
85
signed conditional jumps: JL, JLE, JG, JGE, … e.g. JL (jump if less) checks SF + OF
unsigned conditional jumps: JA, JAE, JB, JBE, … e.g. JB (jump if below) checks CF
86
signed conditional jumps: JL, JLE, JG, JGE, … e.g. JL (jump if less) checks SF + OF
unsigned conditional jumps: JA, JAE, JB, JBE, … e.g. JB (jump if below) checks CF
86
87
✘ ❳❳❳❳❳❳ ❳
87
✘ ❳❳❳❳❳❳ ❳
87
✘ ❳❳❳❳ ❳
88
88
89
✘ ❳❳❳❳❳ ❳
90
✘ ❳❳❳❳❳ ❳
90
✘ ❳❳❳❳❳ ❳
90
✘ ❳❳❳❳❳ ❳
90
✘ ❳❳❳❳❳ ❳
90
91
head
item: 42 next: NULL
92
head
item: 42 next: NULL
92
head
item: 42 next: NULL
92
head
item: 42 next: NULL
92
array
somewhere on heap
93
array
somewhere on heap
93
94
95
95
95
96