aboutsummaryrefslogtreecommitdiff
path: root/pu2/code/lib.i2
diff options
context:
space:
mode:
Diffstat (limited to 'pu2/code/lib.i2')
-rw-r--r--pu2/code/lib.i237
1 files changed, 37 insertions, 0 deletions
diff --git a/pu2/code/lib.i2 b/pu2/code/lib.i2
new file mode 100644
index 0000000..e619fd8
--- /dev/null
+++ b/pu2/code/lib.i2
@@ -0,0 +1,37 @@
+// standard library for i2
+
+macro puts(2) {
+ @1 = 0; // write
+ @2 = /1/; // ptr
+ @3 = /2/; // size
+ system(); // interrupt
+}
+
+macro putchar(1) {
+ @1 = 0; // write
+ @2 = 10; // ptr
+ @3 = 1; // size
+ @10 = /1/; // value
+ system(); // interrupt
+}
+
+// &str, out_dest
+macro strlen(2) {
+ @20 = /1/; // get reference to var
+ @21 = 0; // char count
+ @22 = *@20;
+ while(@22) {
+ @20++;
+ @22 = *@20;
+ @21++;
+ }
+
+ /2/ = @21;
+}
+
+macro print(1) {
+ strlen([/1/], [@3]);
+ @1 = 0; // write
+ @2 = /1/; // ptr
+ system(); // interrupt
+} \ No newline at end of file