123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- %xdefine chr (rbp-8)
- %xdefine tmp (rbp-16)
- %include "macroses.inc"
- global Fscanf
- global ReadString
- global ReadDecimal
- ;| input
- ;rax == buf
- ;rdi == fd
- ;| output
- ;rdx == last read char
- ReadDecimal:
- push rbp
- mov rbp, rsp
- sub rsp, 8
- mov qword [chr], 0
-
- push rcx
- push rbx
- xor rcx, rcx
- xor rbx, rbx
- .next_iter:
- READ_CHAR chr, rdi
- CHECK_SPECIAL [chr]
- je .is_first_char
-
- cmp byte [chr], '-'
- je .is_neg
- CHECK_NUMBER [chr]
- je .is_number
-
- jmp .ret
- .is_first_char:
- cmp rcx, 0
- je .next_iter
- jmp .ret
- .is_neg:
- cmp rcx, 0
- ja .ret
- neg qword [rax]
- jmp .next_iter
- .is_number:
- sub byte [chr], 48
- mov rbx, [rax]
- imul rbx, 10
- add rbx, [chr]
- mov [rax], rbx
-
- inc rcx
- jmp .next_iter
- .ret:
- mov rdx, [chr]
- pop rbx
- pop rcx
- add rsp, 8
- pop rbp
- ret
-
- ;| input
- ;rax == buf
- ;rdi == fd
- ;| output
- ;rdx == last read char
- ReadString:
- push rbp
- mov rbp, rsp
- sub rsp, 16
-
- mov qword [chr], 0
- push rbx
-
- mov [tmp], rax
- .next_iter:
- READ_CHAR chr, rdi
- CHECK_SPECIAL [chr]
- je .is_first_char
-
- mov bl, [chr]
- mov [rax], bl
- inc rax
- jmp .next_iter
-
- .is_first_char:
- cmp [tmp], rax
- je .next_iter
- jmp .ret
- .ret:
- mov rdx, [chr]
- pop rbx
- add rsp, 16
- pop rbp
- ret
- ;| input
- ; rdi == fd
- ; rax == format
- ; arg == stack
- ;| output
- ; rax == number proccesing chars
- Fscanf:
- push rbp
- mov rbp, rsp
- sub rsp, 8
-
- mov qword [chr], 0
-
- push rcx
- push rdx
- push rbx
- push rdi
-
- xor rbx, rbx
- xor rcx, rcx
- xor rdx, rdx
- .next_iter:
- cmp [rax], byte 0x0
- je .ret
- cmp [rax], byte '%'
- je .format_char
- mov cl, [rax]
- mov [chr], cl
- CHECK_SPECIAL [chr]
- je .special_char
- jmp .default_char
- .format_char:
- inc rax
-
- cmp [rax], byte 's'
- je .read_string
- cmp [rax], byte 'd'
- je .read_decimal
- cmp [rax], byte 'c'
- je .read_char
- jmp .ret
- .read_string:
- push rax
- mov rax, [next_arg]
- cmp dl, 0x0
- je .skip_push_char
-
- mov [chr], dl
- CHECK_SPECIAL [chr]
- je .skip_push_char
- mov [rax], dl
- inc rax
- .skip_push_char:
- call ReadString
- pop rax
- inc rbx
- xor rdx, rdx
- jmp .next_step
-
- .read_decimal:
- push rax
- mov rax, [next_arg]
- call ReadDecimal
- pop rax
- inc rbx
- jmp .next_step
-
- .read_char:
- push rax
- cmp dl, 0x0
- je .skip_push_char2
- mov [chr], dl
- CHECK_SPECIAL [chr]
- je .skip_push_char2
-
- mov rcx, [next_arg]
- mov [rcx], dl
- xor rdx, rdx
- jmp .read_char_end
- .skip_push_char2:
- READ_CHAR chr, rdi
- CHECK_SPECIAL [chr]
- je .skip_push_char2
- mov al, [chr]
- mov rcx, [next_arg]
- mov [rcx], al
- .read_char_end:
- pop rax
- inc rbx
- jmp .next_step
- .special_char:
- inc rax
- mov cl, [rax]
- mov [chr], cl
- CHECK_SPECIAL [chr]
- je .special_char
- jmp .next_iter
- .default_char:
- cmp dl, 0x0
- je .skip_push_char3
- cmp dl, [rax]
- je .del_dl
- .del_dl:
- xor rdx, rdx
- jmp .next_step
- jmp .ret
- .skip_push_char3:
- READ_CHAR chr, rdi
- mov cl, [chr]
- cmp cl, [rax]
- je .next_step
- jmp .ret
-
- .next_step:
- inc rax
- jmp .next_iter
-
- .ret:
- mov rax, rbx
- pop rdi
- pop rbx
- pop rdx
- pop rcx
- add rsp, 8
- pop rbp
- ret
|