chore: add macro to simplify constructing opcodes
This commit is contained in:
parent
13dbe31f30
commit
0da0a54b74
@ -56,22 +56,22 @@
|
|||||||
dest (register? dest)]
|
dest (register? dest)]
|
||||||
(when (not dest) (error "dest must be a register"))
|
(when (not dest) (error "dest must be a register"))
|
||||||
(if source-register
|
(if source-register
|
||||||
(bor
|
(construct-opcode
|
||||||
(lshift cond 28)
|
[cond 28]
|
||||||
(lshift 0xd 21)
|
[0xd 21]
|
||||||
(lshift set-flags 20)
|
[set-flags 20]
|
||||||
(lshift dest 12)
|
[dest 12]
|
||||||
source-register)
|
[source-register 0])
|
||||||
(let [rotation (calculate-rotation source)]
|
(let [rotation (calculate-rotation source)]
|
||||||
(when (= nil rotation) (error "Unencodable immediate value"))
|
(when (= nil rotation) (error "Unencodable immediate value"))
|
||||||
(bor
|
(construct-opcode
|
||||||
(lshift cond 28)
|
(cond 28)
|
||||||
(lshift 1 25)
|
(1 25)
|
||||||
(lshift 0xd 21)
|
(0xd 21)
|
||||||
(lshift set-flags 20)
|
(set-flags 20)
|
||||||
(lshift dest 12)
|
(dest 12)
|
||||||
(lshift (/ rotation 2) 8)
|
((/ rotation 2) 8)
|
||||||
(band (util.rotate-left source rotation) 0xff))))))
|
((band (util.rotate-left source rotation) 0xff) 0))))))
|
||||||
|
|
||||||
(fn branch [offset ?options]
|
(fn branch [offset ?options]
|
||||||
(let [{: cond} (parse-conditions ?options)
|
(let [{: cond} (parse-conditions ?options)
|
||||||
|
|||||||
5
test.fnl
Normal file
5
test.fnl
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
(local t (require :deps.faith))
|
||||||
|
|
||||||
|
(local default-modules [:test.assembler.opcodes])
|
||||||
|
|
||||||
|
(t.run (if (= 0 (length arg)) default-modules arg))
|
||||||
@ -1,2 +1,13 @@
|
|||||||
(local t (require :deps.faith))
|
(local t (require :deps.faith))
|
||||||
(local opcodes (require :host.assembler.opcodes))
|
(local {: r : move} (require :host.assembler.opcodes))
|
||||||
|
(fn hex [n]
|
||||||
|
"format a number as 32 bit hexadecimal"
|
||||||
|
(string.format :0x%08x n))
|
||||||
|
|
||||||
|
(fn test-move []
|
||||||
|
(t.= 0xe1a05003
|
||||||
|
(move (r 5) (r 3)))
|
||||||
|
(t.= 0xe3a05003
|
||||||
|
(move (r 5) 3)))
|
||||||
|
|
||||||
|
{: test-move}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user