include "linux_syscall.inc"

;; rdi contains the address of the null-terminated string to print to STDOUT
print_c_string:
   ;; initialize counter
   mov rax, 0

   ;; initialize character pointer
   mov rbx, rdi

.loop:
   ;; Is the current character \0?
   cmp byte [rbx], 0

   ;; If so we can print
   je .print

   ;; Otherwise, increment the counter and check the next character
   inc rax
   inc rbx
   jmp .loop

.print:
   ;; rdi is the start point of the string to print
   mov r11, rdi

   ;; rdx contains the number of characters to print
   mov r12, rax

   ;; Write to STDOUT
   write STDOUT, r11, r12

   ret

newline db 10, 0
print_newline:
  write STDOUT, newline, 1
  ret