chore: add macro to simplify constructing opcodes

This commit is contained in:
Fey Naomi Schrewe 2025-10-17 09:13:11 +02:00
parent 5ed27903ed
commit 0791b20f94
2 changed files with 18 additions and 11 deletions

View File

@ -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

View File

@ -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}