summaryrefslogtreecommitdiff
path: root/03/in03
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2021-11-13 17:24:45 -0500
committerpommicket <pommicket@gmail.com>2021-11-13 17:24:45 -0500
commit8bbacdc3316a54b5ef5805701098eb8e81d17986 (patch)
tree0ee2ef75141c7ce0b43072e9c277a0f251bb4584 /03/in03
parenteb2aadf9bfd14d95e27050bc24c6fb70c10d885e (diff)
corrections in 03 compiler, better hello world program!
Diffstat (limited to '03/in03')
-rw-r--r--03/in0337
1 files changed, 29 insertions, 8 deletions
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