generated from CPP-KT/template-task
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lc.asm
81 lines (64 loc) · 2.25 KB
/
lc.asm
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
sys_exit: equ 60
section .text
global _start
buf_size: equ 8192
_start:
xor ebx, ebx
sub rsp, buf_size
mov rsi, rsp
read_again:
xor eax, eax
xor edi, edi
mov rdx, buf_size
syscall
test rax, rax
jz quit
js read_error
xor ecx, ecx
check_char:
cmp rcx, rax
je read_again
cmp byte [rsi + rcx], 0x0a
jne skip
inc rbx
skip:
inc rcx
jmp check_char
quit:
mov rax, rbx
call print_int
mov rax, sys_exit
xor rdi, rdi
syscall
; rax -- number to print
print_int:
mov rsi, rsp
mov ebx, 10
dec rsi
mov byte [rsi], 0x0a
next_char:
xor edx, edx
div ebx
add dl, '0'
dec rsi
mov [rsi], dl
test rax, rax
jnz next_char
mov eax, 1
mov edi, 1
mov rdx, rsp
sub rdx, rsi
syscall
ret
read_error:
mov eax, 1
mov edi, 2
mov rsi, read_error_msg
mov rdx, read_error_len
syscall
mov rax, sys_exit
mov edi, 1
syscall
section .rodata
read_error_msg: db "read failure", 0x0a
read_error_len: equ $ - read_error_msg