wrote print.dsa
This commit is contained in:
+35
-15
@@ -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 "<relative path>""
|
||||
//
|
||||
// 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
|
||||
// set current to
|
||||
stw rg1, current
|
||||
jmp 4, ret
|
||||
+13
-31
@@ -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
|
||||
// call
|
||||
jmp print::print
|
||||
hlt
|
||||
Binary file not shown.
Reference in New Issue
Block a user