diff options
author | fxqnlr <[email protected]> | 2024-09-19 20:06:53 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-09-19 20:06:53 +0200 |
commit | f0b8e96b51b1a8b19365c9d010639c8d67a42506 (patch) | |
tree | 36a217aa03f7174ddfdbb34736f2288072bda4af /main.asm | |
download | asmsite-f0b8e96b51b1a8b19365c9d010639c8d67a42506.tar asmsite-f0b8e96b51b1a8b19365c9d010639c8d67a42506.tar.gz asmsite-f0b8e96b51b1a8b19365c9d010639c8d67a42506.zip |
initial commit
Diffstat (limited to 'main.asm')
-rw-r--r-- | main.asm | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/main.asm b/main.asm new file mode 100644 index 0000000..7644482 --- /dev/null +++ b/main.asm | |||
@@ -0,0 +1,59 @@ | |||
1 | include 'sys.asm' | ||
2 | |||
3 | format ELF64 executable | ||
4 | |||
5 | segment writable readable | ||
6 | struc db [data] | ||
7 | { | ||
8 | common | ||
9 | . db data | ||
10 | .size = $ - . | ||
11 | } | ||
12 | stat_msg db 'Get file stats', 10 | ||
13 | open_msg db 'Open file', 10 | ||
14 | read_msg db 'Read file', 10 | ||
15 | close_msg db 'Close file', 10 | ||
16 | msg_dn db ':', 10 | ||
17 | |||
18 | indexname db 'index.html' | ||
19 | ;; indexstat stat | ||
20 | indexlen rq 1 | ||
21 | |||
22 | indexfd dd 0 | ||
23 | indexbuf dd ? | ||
24 | indexbuf_len rq 1 | ||
25 | |||
26 | segment readable executable | ||
27 | |||
28 | entry _main | ||
29 | _main: | ||
30 | ls_write STDOUT, open_msg, open_msg.size | ||
31 | ls_open indexname, O_RDONLY, 0 | ||
32 | mov qword [indexfd], rax | ||
33 | cmp [indexfd], 0 | ||
34 | jl error | ||
35 | |||
36 | ls_write STDOUT, read_msg, read_msg.size | ||
37 | ls_read qword [indexfd], indexbuf, indexbuf_len | ||
38 | cmp qword rax, 0 | ||
39 | jl error | ||
40 | mov [indexlen], rax | ||
41 | |||
42 | ls_write STDOUT, close_msg, close_msg.size | ||
43 | ls_close qword [indexfd] | ||
44 | cmp qword rax, 0 | ||
45 | jl error | ||
46 | |||
47 | ls_write STDOUT, indexname, indexname.size | ||
48 | ls_write STDOUT, msg_dn, msg_dn.size | ||
49 | ls_write STDOUT, indexbuf, [indexlen] | ||
50 | cmp qword rax, 0 | ||
51 | jl error | ||
52 | |||
53 | |||
54 | |||
55 | ls_exit 0 | ||
56 | |||
57 | error: | ||
58 | ls_close qword [indexfd] | ||
59 | ls_exit 1 | ||