Added asmc package
This commit is contained in:
58
src/asmc/move.go
Normal file
58
src/asmc/move.go
Normal file
@ -0,0 +1,58 @@
|
||||
package asmc
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/asm"
|
||||
"git.akyoto.dev/cli/q/src/config"
|
||||
"git.akyoto.dev/cli/q/src/x86"
|
||||
)
|
||||
|
||||
func (c *compiler) move(x asm.Instruction) {
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterNumber:
|
||||
c.code = x86.MoveRegisterNumber(c.code, operands.Register, operands.Number)
|
||||
|
||||
case *asm.RegisterRegister:
|
||||
c.code = x86.MoveRegisterRegister(c.code, operands.Destination, operands.Source)
|
||||
|
||||
case *asm.RegisterLabel:
|
||||
start := len(c.code)
|
||||
c.code = x86.MoveRegisterNumber(c.code, operands.Register, 0x00_00_00_00)
|
||||
size := 4
|
||||
opSize := len(c.code) - size - start
|
||||
regLabel := x.Data.(*asm.RegisterLabel)
|
||||
|
||||
if strings.HasPrefix(regLabel.Label, "data_") {
|
||||
c.dataPointers = append(c.dataPointers, &pointer{
|
||||
Position: Address(len(c.code) - size),
|
||||
OpSize: uint8(opSize),
|
||||
Size: uint8(size),
|
||||
Resolve: func() Address {
|
||||
destination, exists := c.dataLabels[regLabel.Label]
|
||||
|
||||
if !exists {
|
||||
panic("unknown label")
|
||||
}
|
||||
|
||||
return Address(destination)
|
||||
},
|
||||
})
|
||||
} else {
|
||||
c.codePointers = append(c.codePointers, &pointer{
|
||||
Position: Address(len(c.code) - size),
|
||||
OpSize: uint8(opSize),
|
||||
Size: uint8(size),
|
||||
Resolve: func() Address {
|
||||
destination, exists := c.codeLabels[regLabel.Label]
|
||||
|
||||
if !exists {
|
||||
panic("unknown label")
|
||||
}
|
||||
|
||||
return config.BaseAddress + c.codeStart + destination
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user