-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmemory.S
92 lines (71 loc) · 1.3 KB
/
memory.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
memory_label: .ascii "Memory "
print_memory:
mov rsi, offset memory_symbol
mov rcx, 6
call print
mov rsi, offset accent1
mov rcx, 5
call print
mov rsi, offset memory_label
mov rcx, 10
call print
mov rsi, offset separator_symbol
mov rcx, 8
call print
mov rax, memtotal
sub rax, memavailable
mov r8, rax
call print_memory_number
mov rsi, offset size_label_0
mov rcx, 7
call print
mov rax, memtotal
call print_memory_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, memtotal
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_memory_number:
imul rax, 1000
mov rbx, 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_memory_zero
call print
print_memory_decimal:
mov byte ptr [print_buf + r10], '.'
inc r10
mov rcx, 2
call print
ret
print_memory_zero:
mov byte ptr [print_buf + r10], '0'
inc r10
jmp print_memory_decimal