push and pop
This commit is contained in:
@@ -115,6 +115,20 @@ impl Encoder {
|
||||
self.data.push(0xc3);
|
||||
}
|
||||
|
||||
pub fn push(&mut self, reg: Reg) {
|
||||
if reg.gt8() {
|
||||
self.data.push(0x41);
|
||||
}
|
||||
self.data.push(0x50 | reg.base());
|
||||
}
|
||||
|
||||
pub fn pop(&mut self, reg: Reg) {
|
||||
if reg.gt8() {
|
||||
self.data.push(0x41);
|
||||
}
|
||||
self.data.push(0x58 | reg.base());
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
@@ -129,11 +143,13 @@ impl Encoder {
|
||||
pub fn asm(&mut self, instr: Instr) -> Result<(), CompilerMsg> {
|
||||
match instr {
|
||||
Instr::Mov { dst, src } => self.mov(dst, src)?,
|
||||
Instr::Int { code } => self.int(code),
|
||||
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(),
|
||||
Instr::Push(reg) => self.push(reg),
|
||||
Instr::Pop(reg) => self.pop(reg),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user