wrote print.dsa
This commit is contained in:
+35
-15
@@ -1,25 +1,45 @@
|
|||||||
// PRINT LIBRARY.
|
// lib:
|
||||||
// don't run this as a program as it won't do anything useful.
|
// 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 display: 0x20000
|
||||||
|
dw current: 0x20000
|
||||||
|
|
||||||
start:
|
reset:
|
||||||
|
pop ret
|
||||||
|
ldw display, rg1
|
||||||
|
stw rg1, current
|
||||||
|
jmp 4, ret
|
||||||
|
|
||||||
|
print:
|
||||||
pop ret // return address
|
pop ret // return address
|
||||||
pop rg0 // length
|
pop rg0 // string
|
||||||
pop rg1 // string
|
ldw current, rg1
|
||||||
ldw display, rg2
|
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
ldw rg1, acc
|
ldb rg0, acc
|
||||||
stw acc, rg2
|
stb acc, rg1
|
||||||
|
|
||||||
dec rg0
|
iadd rg0, 1
|
||||||
|
iadd rg1, 1
|
||||||
|
|
||||||
iadd rg1, 4
|
cmp acc, zero
|
||||||
iadd rg2, 4
|
jne loop
|
||||||
|
|
||||||
cmp rg0, zero
|
|
||||||
jge loop
|
|
||||||
|
|
||||||
|
// return
|
||||||
end:
|
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"
|
include print "../resources/dsa/print.dsa"
|
||||||
dw len: 8
|
|
||||||
|
init:
|
||||||
|
dw stack: 0x10000
|
||||||
|
ldw stack, bpr
|
||||||
|
mov bpr, spr
|
||||||
|
|
||||||
start:
|
start:
|
||||||
// we use lwi in this case because
|
db string: "Damn this works pretty well"
|
||||||
// in a generic case 'string' could be a 32 bit addr
|
|
||||||
lwi string, rg1
|
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:
|
// call
|
||||||
pop ret // return address
|
jmp print::print
|
||||||
pop rg0 // length
|
hlt
|
||||||
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
|
|
||||||
Binary file not shown.
Reference in New Issue
Block a user