Commit a868a785 authored by Nick's avatar Nick
Browse files

all-fixed

parent 7b9df1d5
Pipeline #121329 passed with stage
in 7 seconds
......@@ -18,7 +18,7 @@ exit:
; Переводит строку (выводит символ с кодом 0xA)
print_newline:
xor rax, rax
mov rdi, 10; newline char
mov rdi, `\n`; newline char
ret
......@@ -107,6 +107,20 @@ parse_uint:
.fin:
mov rdx, r8; (task)
ret
; Выводит знаковое 8-байтовое число в десятичном формате
print_int:
;; funny fact: i got en error with "-1" test (output was some big number) then i added line "mov rdi, -1" so i passed it and moved to another test, then i deleted that and all started working fine xd
cmp rdi, 0 ; sets SF ZF CF OF, but test rdi, rdi sets only ZF SF PF so won't work here
;jumps if CF = OF
jge .jump_to_print_uint; if >=0 it is unsigned number
;<0
neg rdi; now rdi >0
push rdi; save or it will be lost
mov rdi, '-' ;aka minus
call print_char; print minus ; -8 = 16
pop rdi;
.jump_to_print_uint:
;can do: jmp print_uint; but can just change function order to "auto" transition
; Выводит беззнаковое 8-байтовое число в десятичном формате
; Совет: выделите место в стеке и храните там результаты деления
; Не забудьте перевести цифры в их ASCII коды.
......@@ -130,25 +144,9 @@ print_uint:
jnz .loop ; if not zero -> continue
mov rdi, r8; get first digit address stored at stack
call print_string; -8 = 32 total %16
add rsp, 24
ret
; Выводит знаковое 8-байтовое число в десятичном формате
print_int:
;; funny fact: i got en error with "-1" test (output was some big number) then i added line "mov rdi, -1" so i passed it and moved to another test, then i deleted that and all started working fine xd
cmp rdi, 0 ; sets SF ZF CF OF, but test rdi, rdi sets only ZF SF PF so won't work here
;jumps if CF = OF
jge .call_print_uint; if >=0 it is unsigned number
;<0
neg rdi; now rdi >0
push rdi; save or it will be lost
mov rdi, '-' ;aka minus
call print_char; print minus ; -8 = 16
pop rdi;
.call_print_uint:
sub rsp, 8 ; -8
call print_uint; -16
add rsp, 8
add rsp, 24 ; can't change call + ret = jmp here because we need to restore stack with add;
ret
; Принимает два указателя на нуль-терминированные строки, возвращает 1 если они равны, 0 иначе
string_equals:
xor rax, rax; rax = 0
......@@ -204,21 +202,21 @@ read_word:
.initial_spaces_loop:
call read_char ;read 1 char
cmp rax, space_sym ; if space -> next
cmp rax, ' ' ; if space -> next
je .initial_spaces_loop
cmp rax, newline ; if newline -> next
cmp rax, `\n` ; if newline -> next
je .initial_spaces_loop
cmp rax, tab ; if tab -> next
cmp rax, `\t` ; if tab -> next
je .initial_spaces_loop
.loop:
cmp rax, null_terminator ; null-terminator -> end
je .fin
cmp rax, space_sym ; space -> end
cmp rax, ' ' ; space -> end
je .fin
cmp rax, tab ; etc
cmp rax, `\t` ; etc
je .fin
cmp rax, newline
cmp rax, `\n`
je .fin
dec r13 ; buffer size -= 1
......@@ -240,7 +238,7 @@ read_word:
mov r12, rdi ; need to save rdi because it'll lost and lead to segfault
call string_length ; rax <- len ; -8 = 16 (alinged)
mov rdx, rax ; rdx <- len (task)
;can't replace to jmp here too, different registers
mov rax, r12 ;buffer addr (task) ;somewhy rdi gets
pop r12; restore r12 (callee-saved)
ret
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment