-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmeminfo.S
66 lines (48 loc) · 817 Bytes
/
meminfo.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
meminfo_file: .asciz "/proc/meminfo"
.lcomm memavailable, 8
.lcomm meminfo_buf, 128
parse_meminfo:
mov rax, SYS_OPEN
mov rdi, offset meminfo_file
xor rsi, rsi
xor rdx, rdx
syscall
mov rdi, rax
mov rax, SYS_READ
mov rsi, offset meminfo_buf
mov rdx, 127
syscall
cmp rax, 127
je meminfo_available
ret
meminfo_available:
xor r8, r8
xor r9, r9
xor r11, r11
skip_line:
mov bl, [meminfo_buf + r8]
inc r8
cmp bl, '\n'
jne skip_line
inc r9
cmp r9, 2
jne skip_line
add r8, 13
skip_space:
mov bl, [meminfo_buf + r8]
inc r8
cmp bl, ' '
je skip_space
parse_memavailable:
mov [number_buf + r11], bl
inc r11
mov bl, [meminfo_buf + r8]
inc r8
cmp bl, ' '
je meminfo_done
jmp parse_memavailable
meminfo_done:
mov rsi, offset number_buf
call atoi
mov memavailable, rax
ret