diff options
author | Irene Knapp <ireneista@irenes.space> | 2025-10-11 08:25:53 -0700 |
---|---|---|
committer | Irene Knapp <ireneista@irenes.space> | 2025-10-11 08:25:53 -0700 |
commit | b65d8ef9072adc928a943633ff30cac610a66684 (patch) | |
tree | 0c8ee716a1c7851c5c4ace851f0bb5bbbab0716e | |
parent | 83984885dcd23109a19d93da4789ad447dc4c451 (diff) |
clean up mnemonics a bit
Force-Push: yes Change-Id: I71ad8876fa9c0bdae9c12f1661b084918a1cb61d
-rw-r--r-- | quine.asm | 87 |
1 files changed, 46 insertions, 41 deletions
diff --git a/quine.asm b/quine.asm index f38f3c4..ab4f13a 100644 --- a/quine.asm +++ b/quine.asm @@ -35,16 +35,10 @@ macro sib scale, index, base db (scale shl 6) or (index shl 3) or base end macro -macro mov.b target, source - match =rax?, target - db 0xB8 - dd source - else match =rdi?, target - db 0xBF - dd source - else - assert 0 - end match +macro opcodereg opcode, reg + assert opcode >= 0 & opcode < 256 & opcode and 7 = 0 + assert reg >= 0 & reg < 8 + db opcode or reg end macro macro qwordreg result, register @@ -70,7 +64,22 @@ macro qwordreg result, register end macro -macro mov.d.dimm target, source +; TODO what register size does this use? +macro mov.b target, source + match =rax?, target + db 0xB8 + dd source + else match =rdi?, target + db 0xBF + dd source + else + assert 0 + end match +end macro + + +; TODO what register size does this use? +macro mov.dreg.dimm target, source rex.w db 0xC7 qwordreg reg, target @@ -79,35 +88,30 @@ macro mov.d.dimm target, source end macro -macro mov.q target, source - match =rax, target - rex.w - db 0xB8 - dq source - else match =rdi, target - rex.w - db 0xBF - dq source - else match =rsi, target +macro mov.qreg.qimm target, source + rex.w + qwordreg treg, target + opcodereg 0xB8, treg + dq source +end macro + + +macro mov.qreg.qreg target, source + match =rsi, target match =rsp, source rex.w db 0x89 modrm 3, 4, 6 else - rex.w - db 0xBE - dq source + assert 0 end match - else match =rdx, target - rex.w - db 0xBA - dq source else assert 0 end match end macro +; TODO what register size does this use? macro add.b target, source match =rax, target rex.w @@ -128,6 +132,7 @@ macro add.q target, source end macro +; TODO what register size does this use? macro sub.b target, source match =rsp, target rex.w @@ -288,7 +293,7 @@ program_header_entry_size = $ - program_header load_origin = 0x08000000 _start: - mov.d.dimm rdx, 0 ; store running file size here + mov.dreg.dimm rdx, 0 ; store running file size here sub.b rsp, 0xFF ; reserve stack space ; ELF header @@ -304,7 +309,7 @@ _start: mov.rel.d rsp, 0x14, 1 ; ELF format version ; Compute the entry pointer. - mov.q rax, load_origin + mov.qreg.qimm rax, load_origin add.b rax, 120 mov.rel.q rsp, 0x18, rax ; entry point @@ -336,13 +341,13 @@ _start: ; for relocation - will we be ASLR'd? ; Add the size of the ELF header to the running total - mov.d.dimm rax, 0x78 + mov.dreg.dimm rax, 0x78 add.q rdx, rax ; Go back and fill in the file size now that we know it. ; so notionally, let's pretend rdx is a variable that keeps track of file ; size. we would do something to populate it, then we would add it to rax... - mov.q rax, 0x185 + mov.qreg.qimm rax, 0x185 add.q rdx, rax ; TODO of course, really we want to for-real track these mov.rel.q rsp, 0x60, rdx ; size in file @@ -353,23 +358,23 @@ _start: ; write() from stack-allocated buffer mov.b rax,1 - mov.q rdi, 1 - mov.q rsi, rsp - mov.q rdx, 0x78 + mov.qreg.qimm rdi, 1 + mov.qreg.qreg rsi, rsp + mov.qreg.qimm rdx, 0x78 syscall ; write() hardcoded header mov.b rax, 1 - mov.q rdi, 1 - mov.q rsi, elf_header + 0x78 - mov.q rdx, file_size - 0x78 + mov.qreg.qimm rdi, 1 + mov.qreg.qimm rsi, elf_header + 0x78 + mov.qreg.qimm rdx, file_size - 0x78 syscall ; write() greeting mov.b rax, 1 - mov.q rdi, 2 - mov.q rsi, greeting - mov.q rdx, greeting_size + mov.qreg.qimm rdi, 2 + mov.qreg.qimm rsi, greeting + mov.qreg.qimm rdx, greeting_size syscall ; exit() |