x86_64 call & ret

This commit is contained in:
2026-06-06 23:26:17 -04:00
parent 69cd249671
commit 66710370bf
5 changed files with 26 additions and 1 deletions
+11
View File
@@ -106,6 +106,15 @@ impl Encoder {
self.data.extend([0x0f, 0x05])
}
pub fn call(&mut self, sym: Symbol) {
self.data.push(0xe8);
self.sym_offset4(sym);
}
pub fn ret(&mut self) {
self.data.push(0xc3);
}
/// inserts a 32 bit offset from a symbol
pub fn sym_offset4(&mut self, sym: Symbol) {
let Some(addr) = self.sym_tab.get(sym) else {
@@ -123,6 +132,8 @@ impl Encoder {
Instr::Int { code } => self.int(code),
Instr::Syscall => self.syscall(),
Instr::Lea { dst, sym } => self.lea(dst, sym),
Instr::Call(sym) => self.call(sym),
Instr::Ret => self.ret(),
}
Ok(())
}