From 8bbacdc3316a54b5ef5805701098eb8e81d17986 Mon Sep 17 00:00:00 2001 From: pommicket Date: Sat, 13 Nov 2021 17:24:45 -0500 Subject: corrections in 03 compiler, better hello world program! --- 03/in03 | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to '03/in03') diff --git a/03/in03 b/03/in03 index dcbf395..ef0640a 100644 --- a/03/in03 +++ b/03/in03 @@ -1,14 +1,35 @@ ; write to stdout -J=d1 -I=:hello_world -D=:hello_world_end -; calculate length by subtracting end from start -D-=I -syscall d1 -J=d42 +B=:hello_world +call :puts +J=d0 syscall x3c :hello_world str Hello, world! xa -:hello_world_end +x0 + +; output null-terminated string in rbx +:puts + call :strlen + I=D + D=A + J=d1 + syscall d1 + return + +; calculate length of string in rbx +; keeps pointer to start of string in rdx, end of string in rsi +:strlen + ; keep pointer to start of string + D=B + I=B + :strlen_loop + C=1I + ?C=0:strlen_loop_end + I+=d1 + !:strlen_loop + :strlen_loop_end + I-=D + A=I + return -- cgit v1.2.3