Implements print_str function.
This commit is contained in:
parent
5f5a34d736
commit
85da24cfe6
1 changed files with 34 additions and 21 deletions
|
@ -1,38 +1,51 @@
|
||||||
|
|
||||||
|
; Just print a "START" flag
|
||||||
[i0:arg] syscall [ci:1] 'S'
|
[i0:arg] syscall [ci:1] 'S'
|
||||||
|
|
||||||
push 1
|
|
||||||
push 2
|
|
||||||
push 3
|
|
||||||
push 4
|
|
||||||
|
|
||||||
cpget
|
push 0 ; pushs string pointer argument
|
||||||
jmp @print_str
|
cpget ; pushs return addr
|
||||||
|
jmp @print_str ; Calls print_str(0)
|
||||||
|
drop ; releases argument
|
||||||
|
|
||||||
|
|
||||||
|
; Print the "END" marker
|
||||||
[i0:arg] syscall [ci:1] 'Q'
|
[i0:arg] syscall [ci:1] 'Q'
|
||||||
|
|
||||||
syscall [ci:0] ; Exit
|
; End the program
|
||||||
|
syscall [ci:0]
|
||||||
|
|
||||||
|
; void print_str(char *string);
|
||||||
print_str:
|
print_str:
|
||||||
spget
|
spget ; enter function by
|
||||||
bpset
|
bpset ; saving the parents base pointer
|
||||||
|
|
||||||
push 200
|
; char *ptr = string;
|
||||||
get -1
|
get -1 ; get argument 0 into our local variable '#1'
|
||||||
get -2
|
|
||||||
get -3
|
|
||||||
get -4
|
|
||||||
push 400
|
|
||||||
|
|
||||||
get 1
|
; 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)
|
||||||
|
|
||||||
push 600
|
; putc(c);
|
||||||
|
[i0:pop] syscall [ci:1] ; removes the loaded character and prints it
|
||||||
|
|
||||||
|
; ptr++;
|
||||||
|
[i0:arg] add 1 ; adds 1 to the stack top
|
||||||
|
|
||||||
|
; }
|
||||||
|
jmp @print_str_loop
|
||||||
|
|
||||||
bpget
|
print_str_end_loop:
|
||||||
spset
|
drop ; discard the result from loadi
|
||||||
jmpi
|
drop ; discard our pointer
|
||||||
|
|
||||||
|
; return
|
||||||
|
bpget ; leave function
|
||||||
|
spset ; by restoring parent base pointer
|
||||||
|
jmpi ; and jumping back.
|
||||||
|
|
||||||
; load 0
|
; load 0
|
||||||
; load 1
|
; load 1
|
||||||
|
|
Loading…
Reference in a new issue