-
Notifications
You must be signed in to change notification settings - Fork 4
/
storage.S
111 lines (85 loc) · 1.64 KB
/
storage.S
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
storage_label: .ascii "Storage "
statfs_path: .asciz "/"
.lcomm statfs_buf, 128
print_storage:
mov rax, SYS_STATFS
mov rdi, offset statfs_path
mov rsi, offset statfs_buf
syscall
mov rsi, offset storage_symbol
mov rcx, 6
call print
mov rsi, offset accent1
mov rcx, 5
call print
mov rsi, offset storage_label
mov rcx, 10
call print
mov rsi, offset separator_symbol
mov rcx, 8
call print
mov rax, [statfs_buf + 16]
test rax, rax
jne print_storage_numbers
mov rsi, offset unknown_label
mov rcx, 7
call println
ret
print_storage_numbers:
sub rax, [statfs_buf + 24]
mov r8, rax
call print_storage_number
mov rsi, offset size_label_0
mov rcx, 7
call print
mov rax, [statfs_buf + 16]
call print_storage_number
mov rsi, offset size_label_1
mov rcx, 6
call print
mov rsi, offset accent0
mov rcx, 5
call print
mov rax, r8
imul rax, 100
mov rbx, [statfs_buf + 16]
xor rdx, rdx
div rbx
mov rbx, 10
mov rdi, offset number_buf
call itoa
add rsi, offset number_buf
call print
mov byte ptr [print_buf + r10], '%'
inc r10
mov rsi, offset reset
mov rcx, 4
call print
mov rsi, offset size_label_2
mov rcx, 2
call print
ret
print_storage_number:
imul rax, [statfs_buf + 8]
imul rax, 1000
mov rbx, 1024 * 1024 * 1024
xor rdx, rdx
div rbx
mov rbx, 10
mov rdi, offset number_buf
call itoa
add rsi, offset number_buf
sub rcx, 3
cmp rcx, 1
jl print_storage_zero
call print
print_storage_decimal:
mov byte ptr [print_buf + r10], '.'
inc r10
mov rcx, 2
call print
ret
print_storage_zero:
mov byte ptr [print_buf + r10], '0'
inc r10
jmp print_storage_decimal