Implemented register push and pop

This commit is contained in:
2024-06-25 16:19:47 +02:00
parent 2cbc064f14
commit a87775a1db
6 changed files with 128 additions and 6 deletions

View File

@ -48,11 +48,23 @@ func (a *Assembler) Finalize() ([]byte, []byte) {
case DIV:
switch operands := x.Data.(type) {
case *RegisterNumber:
code = x64.MoveRegReg64(code, x64.RAX, operands.Register)
code = x64.MoveRegNum32(code, operands.Register, uint32(operands.Number))
code = x64.ExtendRAXToRDX(code)
code = x64.DivReg(code, operands.Register)
code = x64.MoveRegReg64(code, operands.Register, x64.RAX)
if operands.Register == x64.RAX {
code = x64.PushReg(code, x64.RCX)
code = x64.MoveRegNum32(code, x64.RCX, uint32(operands.Number))
code = x64.ExtendRAXToRDX(code)
code = x64.DivReg(code, x64.RCX)
code = x64.PopReg(code, x64.RCX)
} else {
code = x64.PushReg(code, x64.RAX)
code = x64.PushReg(code, x64.RDX)
code = x64.MoveRegReg64(code, x64.RAX, operands.Register)
code = x64.MoveRegNum32(code, operands.Register, uint32(operands.Number))
code = x64.ExtendRAXToRDX(code)
code = x64.DivReg(code, operands.Register)
code = x64.MoveRegReg64(code, operands.Register, x64.RAX)
code = x64.PopReg(code, x64.RDX)
code = x64.PopReg(code, x64.RAX)
}
}
case CALL: