Implemented simple expressions

This commit is contained in:
2024-06-25 20:50:06 +02:00
parent 2569c1bf63
commit e6462266ef
12 changed files with 232 additions and 52 deletions

View File

@ -31,18 +31,24 @@ func (a *Assembler) Finalize() ([]byte, []byte) {
switch operands := x.Data.(type) {
case *RegisterNumber:
code = x64.AddRegNum(code, operands.Register, operands.Number)
case *RegisterRegister:
code = x64.AddRegReg(code, operands.Destination, operands.Source)
}
case SUB:
switch operands := x.Data.(type) {
case *RegisterNumber:
code = x64.SubRegNum(code, operands.Register, operands.Number)
case *RegisterRegister:
code = x64.SubRegReg(code, operands.Destination, operands.Source)
}
case MUL:
switch operands := x.Data.(type) {
case *RegisterNumber:
code = x64.MulRegNum(code, operands.Register, operands.Number)
case *RegisterRegister:
code = x64.MulRegReg(code, operands.Destination, operands.Source)
}
case DIV:
@ -65,6 +71,16 @@ func (a *Assembler) Finalize() ([]byte, []byte) {
code = x64.PopReg(code, x64.RDX)
code = x64.PopReg(code, x64.RAX)
}
case *RegisterRegister:
code = x64.PushReg(code, x64.RAX)
code = x64.PushReg(code, x64.RDX)
code = x64.MoveRegReg64(code, x64.RAX, operands.Destination)
code = x64.ExtendRAXToRDX(code)
code = x64.DivReg(code, operands.Source)
code = x64.MoveRegReg64(code, operands.Destination, x64.RAX)
code = x64.PopReg(code, x64.RDX)
code = x64.PopReg(code, x64.RAX)
}
case CALL: