; Very basic Sublang, without using the standard library Sublib
; Output: Hello, World!
!Print p_string ; Call the macro Print
Z -= Z -1 ; Jumping to -1 halts, equivalent to !Halt
p_string -> &"Hello, World!\n"
Z -> 0 ; Temp register
N_ONE -> -1 ; Store the literal negative one
**
Pure no dependency implementation of print
**
@Print P_STRING? {
; Copy the pointer into the local variable ptr, because we don't want to
; modify the original pointer
Z -= Z ; clear Z
Z -= P_STRING? ; Z = -P_STRING?
ptr -= Z ; ptr = -Z = --P_STRING? = P_STRING?
Z -= Z
.loop ->
char -= char ; Clear char
Z -= (ptr -> 0) ; Z -= *ptr, dereferences ptr to get the actual character
char -= Z .fin ; Flip the character, since it is negative, and jump if
; result is LEQ zero (i.e. finish if it is a ZERO/NULL)
-1 -= char ; Writes the character to the screen. -1 is a special register used
; for IO operations
ptr -= N_ONE ; Increment the pointer to go to the next character
Z -= Z .loop ; Infinite loop
char -> 0 ; This point is never reached, so it is safe to define the
; label 'char' here. It is very important to keep in mind
; that, in this case the zero, will be put in memory in
; this exact place and, if execution crosses it, it will
; be interpreted as an instruction. To define values in between
; instructions, use the '=' operator
.fin ->
}