worked on print.dsa and maths/core.dsa
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// a simple brainf##k interpreter,
|
||||
// because I already wrote a compiler lol.
|
||||
|
||||
include print "./lib/print.dsa"
|
||||
include print "./lib/io/print.dsa"
|
||||
|
||||
// "print hello world"
|
||||
db program: "++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
include print "../io/print.dsa"
|
||||
|
||||
dw idt: 0xFFFF0000
|
||||
|
||||
setup_idt:
|
||||
push bpr
|
||||
mov spr, bpr
|
||||
|
||||
// load the IDT into the IDR
|
||||
ldw idt, idr
|
||||
|
||||
mov bpr, spr
|
||||
pop bpr
|
||||
irt
|
||||
|
||||
setup_hard_fault_handler:
|
||||
push bpr
|
||||
mov spr, bpr
|
||||
|
||||
lwi handle_hard_fault, rg0
|
||||
stw rg0, idr, 4
|
||||
|
||||
mov bpr, spr
|
||||
pop bpr
|
||||
irt
|
||||
|
||||
dw hard_fault_err: "FATAL: Illegal Instruction or Memory Access!"
|
||||
handle_hard_fault:
|
||||
call print::reset
|
||||
lwi hard_fault_err, rg0
|
||||
push rg0
|
||||
call print::print
|
||||
pop zero
|
||||
hlt
|
||||
@@ -4,7 +4,7 @@
|
||||
// usage:
|
||||
//
|
||||
// include print "<relative path>""
|
||||
//
|
||||
//
|
||||
// usage for print:
|
||||
// push (register containing address of string)
|
||||
// push pcx
|
||||
@@ -68,7 +68,7 @@ print_word:
|
||||
jmp _end
|
||||
|
||||
// ------------------------------------------
|
||||
// prints the last byte of arg[0] to the screen.
|
||||
// prints the last byte of arg[0] to the screen.
|
||||
print_byte:
|
||||
push bpr
|
||||
mov spr, bpr
|
||||
@@ -80,6 +80,58 @@ print_byte:
|
||||
addi rg1, 1
|
||||
jmp _end
|
||||
|
||||
// ------------------------------------------
|
||||
// prints the value of arg[0] to the screen in hex.
|
||||
print_hex_byte:
|
||||
push bpr
|
||||
mov spr, bpr
|
||||
|
||||
// put arg byte in rg0
|
||||
ldw bpr, rg0, 8
|
||||
ldw current, rg1
|
||||
|
||||
// mask to get lower nibble
|
||||
lli 0xF, rg2
|
||||
// save rg0 state
|
||||
push rg0
|
||||
|
||||
shr rg0, 4
|
||||
and rg0, rg2, rg0
|
||||
call _print_hex_nibble
|
||||
pop rg0
|
||||
|
||||
and rg0, rg2, rg0
|
||||
call _print_hex_nibble
|
||||
jmp _end
|
||||
|
||||
_print_hex_nibble:
|
||||
lli 10, rg3
|
||||
cmp rg0, rg3
|
||||
jlt _print_hex_nibble_number
|
||||
addi rg0, 0x37, rg0
|
||||
stb rg0, rg1
|
||||
addi rg1, 1
|
||||
jmp _end
|
||||
|
||||
_print_hex_nibble_number:
|
||||
addi rg0, 0x30, rg0
|
||||
stb rg0, rg1
|
||||
addi rg1, 1
|
||||
jmp _end
|
||||
|
||||
// ------------------------------------------
|
||||
// prints the value of arg[0] to the screen in hex.
|
||||
print_hex_word:
|
||||
push bpr
|
||||
mov spr, bpr
|
||||
|
||||
ldw bpr, rg0, 8
|
||||
ldw current, rg1
|
||||
|
||||
stw rg0, rg1
|
||||
addi rg1, 4
|
||||
jmp _end
|
||||
|
||||
// ------------------------------------------
|
||||
// resets the cursor position on the screen to 0x20000. (0,0)
|
||||
reset:
|
||||
@@ -109,7 +161,7 @@ _clear_loop:
|
||||
// return
|
||||
_end:
|
||||
stw rg1, current
|
||||
|
||||
|
||||
mov bpr, spr
|
||||
pop bpr
|
||||
return
|
||||
return
|
||||
@@ -0,0 +1,60 @@
|
||||
// multiply.dsa
|
||||
// usage:
|
||||
//
|
||||
// include multiply "<relative path>"
|
||||
//
|
||||
// usage for multiply:
|
||||
// push (arg1)
|
||||
// push (arg0)
|
||||
// call multiply::multiply
|
||||
// pop (arg0)
|
||||
// pop (arg1)
|
||||
|
||||
multiply:
|
||||
push bpr
|
||||
mov spr, bpr
|
||||
|
||||
ldw bpr, rg0, 8 // load op 2
|
||||
ldw bpr, rg1, 12 // load op 1
|
||||
|
||||
_multiply_loop:
|
||||
add rg2, rg0, rg2
|
||||
dec rg1
|
||||
|
||||
cmp rg1, zero
|
||||
jgt _multiply_loop
|
||||
|
||||
_multiply_end:
|
||||
stw rg2, bpr, 8
|
||||
|
||||
mov bpr, spr
|
||||
pop bpr
|
||||
return
|
||||
|
||||
divmod:
|
||||
push bpr
|
||||
mov spr, bpr
|
||||
|
||||
ldw bpr, rg1, 8 // load op 2
|
||||
ldw bpr, rg0, 12 // load op 1
|
||||
|
||||
lli 0, rg3
|
||||
|
||||
_divmod_loop:
|
||||
cmp rg0, rg1
|
||||
jlt _divmod_end
|
||||
|
||||
sub rg0, rg1, rg0
|
||||
inc rg3
|
||||
|
||||
jmp _divmod_loop
|
||||
|
||||
_divmod_end:
|
||||
// store div in first arg
|
||||
// store mod in second arg
|
||||
stw rg3, bpr, 8
|
||||
stw rg0, bpr, 12
|
||||
|
||||
mov bpr, spr
|
||||
pop bpr
|
||||
return
|
||||
@@ -1,30 +0,0 @@
|
||||
// multiply.dsa
|
||||
// usage:
|
||||
//
|
||||
// include multiply "<relative path>"
|
||||
//
|
||||
// usage for multiply:
|
||||
// push (arg1)
|
||||
// push (arg0)
|
||||
// call multiply::multiply
|
||||
// pop (arg0)
|
||||
// pop (arg1)
|
||||
|
||||
multiply:
|
||||
push bpr
|
||||
mov spr, bpr
|
||||
|
||||
ldw bpr, rg0, 8 // load op 1
|
||||
ldw bpr, rg1, 12 // load op 2
|
||||
|
||||
start:
|
||||
add acc, rg0, acc
|
||||
dec rg1
|
||||
|
||||
cmp rg1, zero
|
||||
jgt start
|
||||
|
||||
end:
|
||||
mov bpr, spr
|
||||
pop bpr
|
||||
return
|
||||
+21
-6
@@ -1,7 +1,8 @@
|
||||
include print "./lib/print.dsa"
|
||||
include print "./lib/io/print.dsa"
|
||||
|
||||
dw idt: 0xFFFF0000
|
||||
dw stack: 0x10000
|
||||
db string: "Hello world"
|
||||
db interrupt: "INT: Hello world"
|
||||
|
||||
init:
|
||||
// set up a stack.
|
||||
@@ -9,10 +10,24 @@ init:
|
||||
mov bpr, spr
|
||||
|
||||
start:
|
||||
lwi string, rg1
|
||||
ldw idt, idr
|
||||
|
||||
push rg1
|
||||
call print::print
|
||||
pop rg1
|
||||
lwi handle_hard_fault, rg0
|
||||
stw rg0, idr, 4
|
||||
|
||||
|
||||
lli 0x20, rg0
|
||||
push rg0
|
||||
call print::print_hex_byte
|
||||
pop zero
|
||||
hlt
|
||||
|
||||
|
||||
dw hard_fault_err: "FATAL: Illegal Instruction or Memory Access!"
|
||||
handle_hard_fault:
|
||||
call print::reset
|
||||
lwi hard_fault_err, rg0
|
||||
push rg0
|
||||
call print::print
|
||||
pop zero
|
||||
hlt
|
||||
|
||||
Reference in New Issue
Block a user