2016-05-21 15:57:25 +00:00
|
|
|
|
|
2016-05-21 22:27:14 +00:00
|
|
|
|
; Just print a "START" flag
|
2016-05-21 19:51:44 +00:00
|
|
|
|
[i0:arg] syscall [ci:1] 'S'
|
2016-05-21 15:57:25 +00:00
|
|
|
|
|
2016-05-21 19:51:44 +00:00
|
|
|
|
|
2016-05-21 22:27:14 +00:00
|
|
|
|
push 0 ; pushs string pointer argument
|
|
|
|
|
cpget ; pushs return addr
|
|
|
|
|
jmp @print_str ; Calls print_str(0)
|
|
|
|
|
drop ; releases argument
|
2016-05-21 19:51:44 +00:00
|
|
|
|
|
2016-05-21 22:27:14 +00:00
|
|
|
|
|
|
|
|
|
; Print the "END" marker
|
2016-05-21 19:51:44 +00:00
|
|
|
|
[i0:arg] syscall [ci:1] 'Q'
|
|
|
|
|
|
2016-05-21 22:27:14 +00:00
|
|
|
|
; End the program
|
|
|
|
|
syscall [ci:0]
|
|
|
|
|
|
|
|
|
|
; void print_str(char *string);
|
|
|
|
|
print_str:
|
2016-05-22 15:17:30 +00:00
|
|
|
|
bpget ; enter function by
|
|
|
|
|
spget ; saving the parents base pointer
|
|
|
|
|
bpset ; and storing the current stack pointer
|
|
|
|
|
|
2016-05-21 19:51:44 +00:00
|
|
|
|
|
2016-05-21 22:27:14 +00:00
|
|
|
|
; char *ptr = string;
|
2016-05-22 15:17:30 +00:00
|
|
|
|
get -2 ; get argument 0 into our local variable '#1'
|
2016-05-21 19:51:44 +00:00
|
|
|
|
|
2016-05-21 22:27:14 +00:00
|
|
|
|
; while(*ptr) {
|
|
|
|
|
print_str_loop:
|
|
|
|
|
[i0:peek] loadi [f:yes] ; write flags, also load result, don't discard pointer
|
|
|
|
|
[ex(z)=1] jmp @print_str_end_loop ; when *ptr == 0, then goto print_str_end_loop
|
|
|
|
|
; char c = *ptr; // which is implicitly done by our while(*ptr)
|
2016-05-21 19:51:44 +00:00
|
|
|
|
|
2016-05-21 22:27:14 +00:00
|
|
|
|
; putc(c);
|
|
|
|
|
[i0:pop] syscall [ci:1] ; removes the loaded character and prints it
|
2016-05-21 19:51:44 +00:00
|
|
|
|
|
2016-05-21 22:27:14 +00:00
|
|
|
|
; ptr++;
|
|
|
|
|
[i0:arg] add 1 ; adds 1 to the stack top
|
2016-05-21 19:51:44 +00:00
|
|
|
|
|
2016-05-21 22:27:14 +00:00
|
|
|
|
; }
|
|
|
|
|
jmp @print_str_loop
|
2016-05-21 19:51:44 +00:00
|
|
|
|
|
2016-05-21 22:27:14 +00:00
|
|
|
|
print_str_end_loop:
|
|
|
|
|
drop ; discard the result from loadi
|
|
|
|
|
drop ; discard our pointer
|
2016-05-21 19:51:44 +00:00
|
|
|
|
|
2016-05-21 22:27:14 +00:00
|
|
|
|
; return
|
|
|
|
|
bpget ; leave function
|
|
|
|
|
spset ; by restoring parent base pointer
|
2016-05-22 15:17:30 +00:00
|
|
|
|
bpset
|
2016-05-21 22:27:14 +00:00
|
|
|
|
jmpi ; and jumping back.
|