Implemented more arm64 instructions

This commit is contained in:
2025-03-13 13:17:58 +01:00
parent dc664dbf5a
commit 5a5061c5d7
23 changed files with 290 additions and 53 deletions

View File

@ -3,7 +3,6 @@ package asmc
import (
"encoding/binary"
"fmt"
"math"
"strings"
"git.urbach.dev/cli/q/src/arm"
@ -37,6 +36,9 @@ func (c *compiler) compileARM(x asm.Instruction) {
}
c.codePointers = append(c.codePointers, pointer)
default:
panic("not implemented")
}
case asm.LABEL:
@ -50,14 +52,79 @@ func (c *compiler) compileARM(x asm.Instruction) {
case asm.TypeMemoryRegister:
operands := c.assembler.Param.MemoryRegister[x.Index]
if operands.Address.OffsetRegister == math.MaxUint8 {
c.append(arm.LoadRegister(operands.Register, operands.Address.Base, int16(operands.Address.Offset), operands.Address.Length))
if operands.Address.OffsetRegister < 0 {
c.append(arm.LoadRegister(operands.Register, operands.Address.Base, int(operands.Address.Offset), operands.Address.Length))
} else {
// TODO: LoadDynamicRegister
panic("not implemented")
}
}
case asm.STORE:
switch x.Type {
case asm.TypeMemoryRegister:
operands := c.assembler.Param.MemoryRegister[x.Index]
if operands.Address.OffsetRegister < 0 {
c.append(arm.StoreRegister(operands.Register, operands.Address.Base, int(operands.Address.Offset), operands.Address.Length))
} else {
panic("not implemented")
}
case asm.TypeMemoryNumber:
operands := c.assembler.Param.MemoryNumber[x.Index]
if operands.Address.OffsetRegister < 0 {
c.append(arm.MoveRegisterNumber(arm.X0, operands.Number))
c.append(arm.StoreRegister(arm.X0, operands.Address.Base, int(operands.Address.Offset), operands.Address.Length))
} else {
panic("not implemented")
}
}
case asm.PUSH:
switch x.Type {
case asm.TypeRegister:
operand := c.assembler.Param.Register[x.Index]
c.append(arm.StorePair(operand.Register, operand.Register, arm.SP, -16))
}
case asm.POP:
switch x.Type {
case asm.TypeRegister:
operand := c.assembler.Param.Register[x.Index]
c.append(arm.LoadPair(operand.Register, operand.Register, arm.SP, 16))
}
case asm.ADD:
switch x.Type {
case asm.TypeRegisterNumber:
operand := c.assembler.Param.RegisterNumber[x.Index]
c.append(arm.AddRegisterNumber(operand.Register, operand.Register, operand.Number))
case asm.TypeRegisterRegister:
panic("not implemented")
}
case asm.SUB:
switch x.Type {
case asm.TypeRegisterNumber:
operand := c.assembler.Param.RegisterNumber[x.Index]
c.append(arm.SubRegisterNumber(operand.Register, operand.Register, operand.Number))
case asm.TypeRegisterRegister:
panic("not implemented")
}
case asm.COMPARE:
switch x.Type {
case asm.TypeRegisterNumber:
operand := c.assembler.Param.RegisterNumber[x.Index]
c.append(arm.SubRegisterNumber(0b11111, operand.Register, operand.Number))
case asm.TypeRegisterRegister:
panic("not implemented")
}
case asm.JE, asm.JNE, asm.JG, asm.JGE, asm.JL, asm.JLE, asm.JUMP:
c.jumpARM(x)
case asm.MOVE:
switch x.Type {
case asm.TypeRegisterRegister: