forked from skx/go.vm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Demonstrate that it works by outputing the length of a string stored in RAM.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# | ||
# This example uses `peek` to read a string character by character | ||
# and output the length of that string. | ||
# | ||
# Unfortunately we can't output the string itself as we have no | ||
# "print character" option. | ||
# | ||
# | ||
|
||
# | ||
# #1 -> Address of string | ||
# | ||
# #0 -> Read each byte here | ||
# | ||
# #3 -> Length of string | ||
# | ||
|
||
store #3, 0x0000 | ||
store #1, string | ||
:loop | ||
peek #0, #1 | ||
inc #1 | ||
inc #3 | ||
cmp #0, 0x00 | ||
jmpnz loop | ||
|
||
# length will be one too many - so decrease by one | ||
dec #3 | ||
|
||
store #1, "The length of the string is " | ||
print_str #1 | ||
print_int #3 | ||
store #1, " bytes\n" | ||
print_str #1 | ||
exit | ||
|
||
:string | ||
DB "Steve" | ||
DB 0x00 |