lang-bootstrap/03/in03

35 lines
451 B
Text

; write to stdout
B=:hello_world
call :puts
J=d0
syscall x3c
:hello_world
str Hello, world!
xa
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