chore: add macro to simplify constructing opcodes
This commit is contained in:
parent
5ed27903ed
commit
0791b20f94
@ -77,19 +77,19 @@
|
||||
(let [{: cond} (parse-conditions ?options)
|
||||
max-immediate 0xffffff
|
||||
offset (band offset util.word-max)]
|
||||
(bor
|
||||
(lshift cond 28)
|
||||
(lshift 10 24)
|
||||
(band (rshift offset 2) 0xffffff))))
|
||||
(construct-opcode
|
||||
(cond 28)
|
||||
(10 24)
|
||||
((band (rshift offset 2) 0xffffff) 0))))
|
||||
|
||||
(fn branch-link [offset ?options]
|
||||
(let [{: cond} (parse-conditions ?options)
|
||||
max-immediate 0xffffff
|
||||
offset (band offset util.word-max)]
|
||||
(bor
|
||||
(lshift cond 28)
|
||||
(lshift 11 24)
|
||||
(band (rshift offset 2) 0xffffff))))
|
||||
(construct-opcode
|
||||
(cond 28)
|
||||
(11 24)
|
||||
((band (rshift offset 2) 0xffffff) 0))))
|
||||
|
||||
{: r
|
||||
: move
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
(local t (require :deps.faith))
|
||||
(local {: r : move} (require :host.assembler.opcodes))
|
||||
|
||||
(local {: r : move : branch : branch-link} (require :host.assembler.opcodes))
|
||||
(fn hex [n]
|
||||
"format a number as 32 bit hexadecimal"
|
||||
(string.format :0x%08x n))
|
||||
@ -11,4 +10,12 @@
|
||||
(t.= 0xe3a05003
|
||||
(move (r 5) 3)))
|
||||
|
||||
{: test-move}
|
||||
(fn test-branch []
|
||||
(t.= 0xea000021
|
||||
(branch 132)))
|
||||
|
||||
(fn test-branch-link []
|
||||
(t.= 0xeb000021
|
||||
(branch-link 132)))
|
||||
|
||||
{: test-move : test-branch : test-branch-link}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user