Skip to content

Commit a4bca5a

Browse files
committed
Added the start of the assembler
1 parent 602bca7 commit a4bca5a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/clj_dcpu16/asm.clj

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(ns clj-dcpu16.asm
2+
(:use [clojure.java.io]))
3+
4+
(def opcode-map {"SET" 0x1 "ADD" 0x2 "SUB" 0x3 "MUL" 0x4 "DIV" 0x5
5+
"MOD" 0x6 "SHL" 0x7 "SHR" 0x8 "AND" 0x9 "BOR" 0xA
6+
"XOR" 0xB "IFE" 0xC "IFN" 0xD "IFG" 0xE "IFB" 0xF
7+
"JSR" 0})
8+
9+
(def comment-regex #"$;.*")
10+
11+
(defn parse [line]
12+
)
13+
14+
(defn parse-lines [lines]
15+
(map parse lines))
16+
17+
(defn first-pass [lines])
18+
19+
(defn second-pass [fp lines])
20+
21+
(defn output [result w])
22+
23+
(defn parse [filename]
24+
(with-open [r (reader filename)
25+
w (writer (str filename ".out"))]
26+
(let [lines (line-seq r)]
27+
(-> lines
28+
parse-lines
29+
first-pass
30+
(second-pass lines)
31+
(output w)))))

0 commit comments

Comments
 (0)