Implemented addition

This commit is contained in:
2024-06-24 14:14:07 +02:00
parent 41f5dcbe62
commit 597cb9abed
6 changed files with 78 additions and 23 deletions

View File

@ -27,21 +27,15 @@ func (a *Assembler) Finalize() ([]byte, []byte) {
for _, x := range a.Instructions {
switch x.Mnemonic {
case MOVE:
case ADD:
switch operands := x.Data.(type) {
case *RegisterNumber:
code = x64.MoveRegNum32(code, operands.Register, uint32(operands.Number))
code = x64.AddRegNum8(code, operands.Register, uint8(operands.Number))
case *RegisterRegister:
code = x64.MoveRegReg64(code, operands.Destination, operands.Source)
// code = x64.AddRegReg64(code, operands.Destination, operands.Source)
}
case RETURN:
code = x64.Return(code)
case SYSCALL:
code = x64.Syscall(code)
case CALL:
code = x64.Call(code, 0x00_00_00_00)
size := 4
@ -77,6 +71,21 @@ func (a *Assembler) Finalize() ([]byte, []byte) {
case LABEL:
labels[x.Data.(*Label).Name] = Address(len(code))
case MOVE:
switch operands := x.Data.(type) {
case *RegisterNumber:
code = x64.MoveRegNum32(code, operands.Register, uint32(operands.Number))
case *RegisterRegister:
code = x64.MoveRegReg64(code, operands.Destination, operands.Source)
}
case RETURN:
code = x64.Return(code)
case SYSCALL:
code = x64.Syscall(code)
default:
panic("Unknown mnemonic: " + x.Mnemonic.String())
}