summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-04-11 03:32:24 -0400
committerbd <bdunahu@operationnull.com>2025-04-11 03:32:24 -0400
commit1904e4e800dcf37becb3bba17c3a3aaca3c7a47c (patch)
treed639d0d37216071462c008345d361358db24b171
parent1161354f5dbb9648f90edb3ffb16dc9daad7d966 (diff)
Add a few new test files
-rw-r--r--input/adjacent-adder-manual.asm (renamed from input/add-loop.asm)6
-rw-r--r--input/adjacent-adder.asm (renamed from input/add-loop-directive.asm)12
-rw-r--r--input/dominative-functions.asm54
-rw-r--r--input/identity.asm59
-rw-r--r--input/rabbits.asm17
-rw-r--r--input/simple.asm5
-rw-r--r--src/main.lisp2
-rw-r--r--src/parse.lisp10
8 files changed, 150 insertions, 15 deletions
diff --git a/input/add-loop.asm b/input/adjacent-adder-manual.asm
index 53520f3..b575959 100644
--- a/input/add-loop.asm
+++ b/input/adjacent-adder-manual.asm
@@ -1,4 +1,10 @@
+;;;;;;;;
+;;; adds adjacent elements of a 4-element vector together,
+;;; storing the result in place.
+;;; Does not make use of variables.
+
.data
+ ;; empty
.text
addi $2 $0 0x200
addi $5 $0 0x1
diff --git a/input/add-loop-directive.asm b/input/adjacent-adder.asm
index 5bccff3..35704d2 100644
--- a/input/add-loop-directive.asm
+++ b/input/adjacent-adder.asm
@@ -1,12 +1,16 @@
+;;;;;;;;
+;;; adds adjacent elements of a 4-element vector together,
+;;; storing the result in place.
+
.data
arr 1 2 3 4
s 3
i 0
.text
- load $5 s
- load $10 arr
- load $6 i
+ addi $5 $5 s
+ addi $10 $10 arr
+ addi $6 $6 i
jrl CMP
L:
add $9 $10 $6
@@ -17,5 +21,5 @@ L:
store $7 0($9)
addi $6 $6 0x1
CMP:
- cmp $6 $5
+ cmp $5 $6
bgt L
diff --git a/input/dominative-functions.asm b/input/dominative-functions.asm
new file mode 100644
index 0000000..cb8564e
--- /dev/null
+++ b/input/dominative-functions.asm
@@ -0,0 +1,54 @@
+;;;;;;;;
+;;; makes use of a designated function to add two numbers together
+;;; uses a stack-based paradigm with a base pointer to manage argument passing
+;;; TODO this file is incomplete due to remaining ISA subroutine design issues
+
+.data
+ answer 0
+
+.text
+MAIN:
+ addi $5 $2 0x0 ; establish frame pointer
+
+ addi $6 $0 -11
+
+ push $6
+ ;; jal SUB23
+ store $6 answer($0)
+SUB23:
+ push $5 ; push old frame pointer
+ addi $5 $2 0x0
+ subi $2 $2 0x4
+
+ addi $6 $0 -23
+ store $6 -4($5)
+
+ load $7 +4($5) ; access argument
+ load $6 -4($5)
+
+ add $6 $6 $7
+ push $6
+ ;; jal ADD76
+ pop $6 ; retrieve and pass along
+ store $6 +4($5)
+
+ addi $2 $5 0x0 ; restore stack pointer
+ pop $5 ; restore frame pointer
+ ;; ret
+ADD76:
+ push $5
+ addi $5 $2 0x0
+ subi $2 $2 0x4
+
+ addi $6 $0 +76
+ store $6 -4($5)
+
+ load $7 +4($5) ; access argument
+ load $6 -4($5)
+
+ add $6 $6 $7
+ store $6 +4($5)
+
+ addi $2 $5 0x0
+ pop $5
+ ;; ret
diff --git a/input/identity.asm b/input/identity.asm
new file mode 100644
index 0000000..e6d9260
--- /dev/null
+++ b/input/identity.asm
@@ -0,0 +1,59 @@
+;;;;;;;;
+;;; performs a matrix multiply on the 4x4 square matrices
+;;; m1 and m2,
+;;; the result of which is placed into
+;;; r,
+;;; in this case, the result is the identity
+;;; does not use designated vector instructions
+
+.data
+ m1 01 00 -1 00 00 01 00 -1 00 00 01 00 00 00 00 01
+ m2 01 00 01 00 00 01 00 01 00 00 01 00 00 00 00 01
+ r 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+.text
+ addi $8 $0 0x4 ; dimensions
+ addi $9 $0 0x0 ; tracks the rows
+ addi $10 $0 0x0 ; tracks the columns
+ jrl ROWCOND
+
+ROW:
+ jrl COLCOND
+COL:
+ addi $11 $0 0x0 ; tracks the element being added
+ addi $12 $0 0x0 ; the accumulated result to place into $9,$10
+
+ mul $7 $9 $8 ; setup the index into m1
+ addi $5 $7 m1
+
+ addi $6 $0 m2 ; setup the index into m2
+ add $6 $6 $10
+
+ jrl ELECOND
+ELE:
+ add $5 $5 $11 ; increment m1
+
+ mul $13 $11 $8 ; increment m2
+ add $6 $6 $13
+
+ load $13 0($5) ; retrieve and accumulate
+ load $14 0($6)
+ add $12 $14 $13
+
+ addi $11 $11 0x1
+ELECOND:
+ cmp $8 $11
+ bgt ELE
+ addi $10 $10 0x1
+COLCOND:
+ cmp $8 $10
+ bgt COL
+
+ add $7 $7 $10 ; setup the index into r
+ addi $7 $7 r
+
+ store $12 0($7)
+
+ addi $9 $9 0x1
+ROWCOND:
+ cmp $8 $9
+ bgt ROW
diff --git a/input/rabbits.asm b/input/rabbits.asm
new file mode 100644
index 0000000..c848116
--- /dev/null
+++ b/input/rabbits.asm
@@ -0,0 +1,17 @@
+;;;;;;;;
+;;; multiplies numbers until an overflow occurs
+
+.data
+ rabbits 2
+ rate 300
+
+.text
+ load $5 rabbits($0)
+ load $6 rate($0)
+
+BREED:
+ mul $5 $5 $6
+ store $5 rabbits($0)
+ bof DONE
+ jrl BREED
+DONE:
diff --git a/input/simple.asm b/input/simple.asm
deleted file mode 100644
index 3e60ee8..0000000
--- a/input/simple.asm
+++ /dev/null
@@ -1,5 +0,0 @@
- addi $sp $0 512
- addi $5 $0 1
- store $5 0($sp)
- addi $5 $0 2
- store $5 1($sp)
diff --git a/src/main.lisp b/src/main.lisp
index 517d395..f1f3021 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -65,7 +65,7 @@ _/_/ _/_/ "
(let ((words (emit:emit ast)))
(if write?
(postprocess words file)
- (format t "Emission successfull, got: ~%~a~%" words)))
+ (format t "Emission successful, got: ~%~a~%" words)))
(format t "Parse successful, got:~%~a~%" (emit:ast->str ast))))
(error "The file does not exist, or it could not be opened.~%")))))))
diff --git a/src/parse.lisp b/src/parse.lisp
index 2e1cf55..f435c0a 100644
--- a/src/parse.lisp
+++ b/src/parse.lisp
@@ -51,14 +51,14 @@
(esrap:defrule variable alphanumeric
(:lambda (e) (list 'emit::var e)))
-(esrap:defrule dereference (and integer #\( register #\))
- (:destructure (i1 w1 r w2)
- (declare (ignore w1 w2))
- (list r (list 'emit::imm i1))))
-
(esrap:defrule immediate (or integer variable)
(:lambda (e) (list 'emit::imm e)))
+(esrap:defrule dereference (and immediate #\( register #\))
+ (:destructure (i1 w1 r w2)
+ (declare (ignore w1 w2))
+ (list r i1)))
+
;;; defines rules to parse labels
(esrap:defrule label alphanumeric