Implemented simple expressions
This commit is contained in:
@ -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:
|
||||
|
Reference in New Issue
Block a user