From 11a107e56d9f30ccd8a653808ee9477dec5ee87a Mon Sep 17 00:00:00 2001 From: zxq5 Date: Thu, 19 Jun 2025 01:57:47 +0100 Subject: [PATCH] wrote print.dsa --- resources/dsa/print.dsa | 50 ++++++++++++++++++++++++++++------------ resources/dsa/test.dsa | 44 +++++++++++------------------------ resources/dsb/test.dsb | Bin 160 -> 196 bytes 3 files changed, 48 insertions(+), 46 deletions(-) diff --git a/resources/dsa/print.dsa b/resources/dsa/print.dsa index 900e0ee..3094f2e 100644 --- a/resources/dsa/print.dsa +++ b/resources/dsa/print.dsa @@ -1,25 +1,45 @@ -// PRINT LIBRARY. -// don't run this as a program as it won't do anything useful. +// lib: +// print.dsa + +// usage: +// +// include print """ +// +// usage for print: +// push (register containing address of string) +// push pcx +// jmp print::print +// +// usage for reset: +// push pcx +// jmp print::reset dw display: 0x20000 +dw current: 0x20000 -start: +reset: + pop ret + ldw display, rg1 + stw rg1, current + jmp 4, ret + +print: pop ret // return address - pop rg0 // length - pop rg1 // string - ldw display, rg2 + pop rg0 // string + ldw current, rg1 loop: - ldw rg1, acc - stw acc, rg2 + ldb rg0, acc + stb acc, rg1 - dec rg0 + iadd rg0, 1 + iadd rg1, 1 - iadd rg1, 4 - iadd rg2, 4 - - cmp rg0, zero - jge loop + cmp acc, zero + jne loop + // return end: - jmp ret \ No newline at end of file + // set current to + stw rg1, current + jmp 4, ret \ No newline at end of file diff --git a/resources/dsa/test.dsa b/resources/dsa/test.dsa index d12de2c..101c8b0 100644 --- a/resources/dsa/test.dsa +++ b/resources/dsa/test.dsa @@ -1,36 +1,18 @@ -dw string: "this is some random string idk" -dw len: 8 +include print "../resources/dsa/print.dsa" + +init: + dw stack: 0x10000 + ldw stack, bpr + mov bpr, spr start: - // we use lwi in this case because - // in a generic case 'string' could be a 32 bit addr + db string: "Damn this works pretty well" lwi string, rg1 - push rg1 - lwi len, rg1 - push rg1 - push pcx - jmp start - hlt -dw display: 0x20000 + // push variables + push rg1 // string address. + push pcx // return address. -print: - pop ret // return address - pop rg0 // length - pop rg1 // string - ldw display, rg2 - -loop: - ldw rg1, acc - stw acc, rg2 - - dec rg0 - - iadd rg1, 4 - iadd rg2, 4 - - cmp rg0, zero - jge loop - -end: - jmp 4, ret \ No newline at end of file + // call + jmp print::print + hlt \ No newline at end of file diff --git a/resources/dsb/test.dsb b/resources/dsb/test.dsb index 5ce7782596d3965be1c965707b43b68b51d8e26d..a0cae0f9d4c0eb76d89e7ebe9fc81c1a64a67b6b 100644 GIT binary patch literal 196 zcmZ9^FAKsz0EY4BLkcOOWyF)U8WFav(Fwy(Z~W7Us^UKhkrKq1ftWk0=Bt^XTOT<#=m literal 160 zcmZ9^u?m7f0D$2?xxuximLtwh>V^|ScZcRSTLYsGQOOfpdxbzqq6hI!d>Myu?ccuT z-!sO*