; Выводит знаковое 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
cmprdi,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
negrdi; now rdi >0
pushrdi; save or it will be lost
movrdi,'-';aka minus
callprint_char; print minus ; -8 = 16
poprdi;
.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
movrdi,r8; get first digit address stored at stack
callprint_string; -8 = 32 total %16
addrsp,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
cmprdi,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
negrdi; now rdi >0
pushrdi; save or it will be lost
movrdi,'-';aka minus
callprint_char; print minus ; -8 = 16
poprdi;
.call_print_uint:
subrsp,8; -8
callprint_uint; -16
addrsp,8
addrsp,24; can't change call + ret = jmp here because we need to restore stack with add;
ret
; Принимает два указателя на нуль-терминированные строки, возвращает 1 если они равны, 0 иначе
string_equals:
xorrax,rax; rax = 0
...
...
@@ -204,21 +202,21 @@ read_word:
.initial_spaces_loop:
callread_char;read 1 char
cmprax,space_sym; if space -> next
cmprax,' '; if space -> next
je.initial_spaces_loop
cmprax,newline; if newline -> next
cmprax,`\n`; if newline -> next
je.initial_spaces_loop
cmprax,tab; if tab -> next
cmprax,`\t`; if tab -> next
je.initial_spaces_loop
.loop:
cmprax,null_terminator; null-terminator -> end
je.fin
cmprax,space_sym; space -> end
cmprax,' '; space -> end
je.fin
cmprax,tab; etc
cmprax,`\t`; etc
je.fin
cmprax,newline
cmprax,`\n`
je.fin
decr13; buffer size -= 1
...
...
@@ -240,7 +238,7 @@ read_word:
movr12,rdi; need to save rdi because it'll lost and lead to segfault
callstring_length; rax <- len ; -8 = 16 (alinged)
movrdx,rax; rdx <- len (task)
;can't replace to jmp here too, different registers