File: mini-libc-mes.hex2

package info (click to toggle)
mescc-tools 1.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,640 kB
  • sloc: ansic: 9,338; asm: 2,350; sh: 360; makefile: 163; lisp: 83
file content (119 lines) | stat: -rw-r--r-- 1,990 bytes parent folder | download | duplicates (3)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
## Copyright (C) 2017 Jeremiah Orians
## This file is part of stage0.
##
## stage0 is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## stage0 is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with stage0.  If not, see <http://www.gnu.org/licenses/>.

## stage0's hex2 format for x86
##    !<label>          1 byte relative
##    $<label>          2 byte address
##    @<label>          2 byte relative
##    %<label>          4 byte relative
##    &<label>          4 byte address
##    label_<label>     function-local
##    string_<count>    string
##

#.text

:_start
55 89 e5 83 ec 40
e8 %main 83 c4 00
89 45 fc
# exit(r);

ff 75 fc
e8 %exit 83 c4 04
85 c0
c9 c3

:_env
55 89 e5 83 ec 40
8b 45 08
c9 c3

:exit
55 89 e5 83 ec 40
# asm(".byte 0x8b 0x5d 0x08");

8b 5d 08
# asm(".byte 0xb8 0x01 0x00 0x00 0x00");

b8 01 00 00 00
# asm(".byte 0xcd 0x80");

cd 80
c9 c3

:write
55 89 e5 83 ec 40
# asm(".byte 0x8b 0x5d 0x08");

8b 5d 08
# asm(".byte 0x8b 0x4d 0x0c");

8b 4d 0c
# asm(".byte 0x8b 0x55 0x10");

8b 55 10
# asm(".byte 0xb8 0x04 0x00 0x00 0x00");

b8 04 00 00 00
# asm(".byte 0xcd 0x80");

cd 80
c9 c3

:strlen
# while (s[i]) ...
55 89 e5 83 ec 40
c7 45 fc 00 00 00 00
e9 09 00 00 00
8b 45 fc
83 45 fc 01
85 c0
8b 45 fc
89 c2
8b 55 08
01 d0
0f b6 00
85 c0
85 c0
84 c0 74 05
e9 dd ff ff ff
8b 45 fc
c9 c3

:eputs
55 89 e5 83 ec 40
ff 75 08
e8 %strlen 83 c4 04
89 45 fc
# write(2, s, i);

ff 75 fc
ff 75 08
b8 02 00 00 00
50
e8 %write 83 c4 0c
85 c0
b8 00 00 00 00
c9 c3

#.data

:g_stdin
00 00 00 00

:g_environment
00 00 00 00