;screenmsg.asm
section .data
LF equ 10
NULL equ 0
TRUE equ 1
FALSE equ 0
EXIT_SUCCESS equ 0
STDIN equ 0
STDOUT equ 1
STDERR equ 2
SYS_read equ 0
SYS_write equ 1
SYS_open equ 2
SYS_close equ 3
SYS_fork equ 57
SYS_exit equ 60
SYS_creat equ 85
SYS_time equ 201

message1 db LF, LF, "MESSAGE 1",LF, LF, NULL
message2 db "MESSAGE 2", LF, NULL
newline db LF, LF, NULL

section .text
global _start
_start:

mov rdi, message1
call printmsg

mov rdi, message2
call printmsg

mov rdi, newline
call printmsg

mov rax, SYS_exit
mov rdi, EXIT_SUCCESS
syscall

global printmsg
printmsg:

push rbx
mov rbx, rdi
mov rsi, rdi       ;address of characters to write
;                  ;I put rsi here, after rdi and before rdx 
mov rdx, 0

stringcountloop:
cmp byte[rbx], NULL
je stringcountdone
inc rdx             ;last inc first
inc rbx             ;first inc after
jmp stringcountloop

stringcountdone:
cmp rdx, 0
je _done

mov rax, SYS_write
;     mov rsi, rdi   ;address of characters to write
;                    ;I move rsi above, after rdi and before rdx
mov rdi, STDOUT

syscall

_done:
pop rbx
ret

