I should go to sleep frfr.
This commit is contained in:
@@ -16,13 +16,13 @@ impl Syntax {
|
|||||||
"xor", "nand", "nor", "xnor", "irt", "int", "hlt",
|
"xor", "nand", "nor", "xnor", "irt", "int", "hlt",
|
||||||
// pseduo-instructions
|
// pseduo-instructions
|
||||||
"db", "dh", "dw", "resb", "resh", "resw", "push", "pop", "lwi", "call",
|
"db", "dh", "dw", "resb", "resh", "resw", "push", "pop", "lwi", "call",
|
||||||
"ret",
|
"include",
|
||||||
]),
|
]),
|
||||||
types: BTreeSet::from([]),
|
types: BTreeSet::from([]),
|
||||||
special: BTreeSet::from([
|
special: BTreeSet::from([
|
||||||
"rg0", "rg1", "rg2", "rg3", "rg4", "rg5", "rg6", "rg7", "rg8", "rg9",
|
"rg0", "rg1", "rg2", "rg3", "rg4", "rg5", "rg6", "rg7", "rg8", "rg9",
|
||||||
"rga", "rgb", "rgc", "rgd", "rge", "rgf", "acc", "spr", "bpr", "ret",
|
"rga", "rgb", "rgc", "rgd", "rge", "rgf", "acc", "spr", "bpr", "ret",
|
||||||
"idr", "mmr", "zero", "null",
|
"idr", "mmr", "zero", "null", "pcx", "mdr", "mar", "sts", "cir",
|
||||||
]),
|
]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-21
@@ -1,27 +1,20 @@
|
|||||||
db fib_count: 10 // How many more numbers to calculate after F(0) and F(1)
|
db fib_count: 10 // How many more numbers to calculate after F(0) and F(1)
|
||||||
|
|
||||||
init:
|
fib_n:
|
||||||
lli 0, rg0 // F(0) = 0
|
pop ret
|
||||||
lli 1, rg1 // F(1) = 1
|
pop rg0 // n
|
||||||
ldb fib_count, rg2
|
|
||||||
|
|
||||||
loop:
|
lli 0, rg1
|
||||||
add rg0, rg1, acc // rg4 = rg0 + rg1 (new Fibonacci number)
|
lli 1, rg2
|
||||||
|
|
||||||
push rg0
|
start:
|
||||||
mov rg1, rg0 // rg0 = previous rg1 (F(n-2) = F(n-1))
|
add rg1, rg2, acc
|
||||||
mov acc, rg1 // rg1 = rg4 (F(n-1) = F(n))
|
push rg1
|
||||||
|
mov rg2, rg1
|
||||||
|
mov acc, rg2
|
||||||
|
|
||||||
dec rg2 // rg2 = rg2 - 1
|
cmp rg0, zero
|
||||||
|
dec rg0
|
||||||
cmp rg2, zero // Compare counter with 0
|
|
||||||
jgt loop // Jump back if counter > 0
|
|
||||||
|
|
||||||
finish:
|
|
||||||
push rg0,
|
|
||||||
push rg1,
|
|
||||||
// Final Fibonacci number is in rg1
|
|
||||||
hlt
|
|
||||||
|
|
||||||
// jmp print::run
|
|
||||||
|
|
||||||
|
jgt start
|
||||||
|
jmp 4, ret
|
||||||
+19
-2
@@ -1,12 +1,15 @@
|
|||||||
include print "../resources/dsa/print.dsa"
|
include print "../resources/dsa/print.dsa"
|
||||||
|
include fib "../resources/dsa/fib.dsa"
|
||||||
|
|
||||||
|
dw stack: 0x10000
|
||||||
|
db string: "Hello world! This is about to be dependency hell..."
|
||||||
|
db string2: "And extremely jank. Ridiculously, unfathomably jank."
|
||||||
|
|
||||||
init:
|
init:
|
||||||
dw stack: 0x10000
|
|
||||||
ldw stack, bpr
|
ldw stack, bpr
|
||||||
mov bpr, spr
|
mov bpr, spr
|
||||||
|
|
||||||
start:
|
start:
|
||||||
db string: "Damn this works pretty well"
|
|
||||||
lwi string, rg1
|
lwi string, rg1
|
||||||
|
|
||||||
// push variables
|
// push variables
|
||||||
@@ -15,4 +18,18 @@ start:
|
|||||||
|
|
||||||
// call
|
// call
|
||||||
jmp print::print
|
jmp print::print
|
||||||
|
|
||||||
|
|
||||||
|
lli 25, rg0
|
||||||
|
push rg0
|
||||||
|
push pcx
|
||||||
|
jmp fib::fib_n
|
||||||
|
|
||||||
|
|
||||||
|
lwi string2, rg1
|
||||||
|
push rg1
|
||||||
|
push pcx
|
||||||
|
|
||||||
|
jmp print::print
|
||||||
|
|
||||||
hlt
|
hlt
|
||||||
Reference in New Issue
Block a user