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.
Added this example of showing a boxed-string
- Loading branch information
Showing
1 changed file
with
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# | ||
# Prompt for a string and then output it, surrounded by a series of | ||
# stars! | ||
# | ||
# | ||
# | ||
store #1, "Please enter your name:" | ||
print_str #1 | ||
|
||
# Reads a string from the console - sets the result in register #0 | ||
int 0x01 | ||
|
||
# The following trap removes the newline from the string in #0 | ||
int 0x02 | ||
|
||
call box | ||
exit | ||
|
||
# | ||
# This function prints out the string in #0 in a box. For example if the input | ||
# string in #0 is "Steve" the output will be: | ||
# | ||
# ********* | ||
# * Steve * | ||
# ********* | ||
# | ||
# Registers ruined: | ||
# #0 | ||
# #1 | ||
# #10 | ||
# | ||
:box | ||
# string is in #0 | ||
store #10, #0 | ||
# find the length | ||
int 0x00 | ||
|
||
# now we want to print the line of stars to box the string | ||
inc #0 | ||
inc #0 | ||
inc #0 | ||
inc #0 | ||
|
||
:header | ||
store #1, "*" | ||
print_str #1 | ||
dec #0 | ||
jmpnz header | ||
|
||
# print "* $str *" | ||
store #1, "\n* " | ||
print_str #1 | ||
store #1, #10 | ||
print_str #1 | ||
store #1, " *\n" | ||
print_str #1 | ||
|
||
# now repeat the process to print stars under the string | ||
store #0, #10 | ||
# find the length | ||
int 0x00 | ||
|
||
# now we want to print the line of stars to box the string | ||
inc #0 | ||
inc #0 | ||
inc #0 | ||
inc #0 | ||
|
||
:footer | ||
store #1, "*" | ||
print_str #1 | ||
dec #0 | ||
jmpnz footer | ||
|
||
store #1, "\n" | ||
print_str #1 | ||
ret |