40 lines
800 B
Go
40 lines
800 B
Go
package asmc
|
|
|
|
import (
|
|
"git.urbach.dev/cli/q/src/asm"
|
|
"git.urbach.dev/cli/q/src/x86"
|
|
)
|
|
|
|
func (c *compiler) call(x asm.Instruction) {
|
|
switch data := x.Data.(type) {
|
|
case *asm.Label:
|
|
c.code = x86.Call(c.code, 0x00_00_00_00)
|
|
size := 4
|
|
|
|
pointer := &pointer{
|
|
Position: Address(len(c.code) - size),
|
|
OpSize: 1,
|
|
Size: uint8(size),
|
|
}
|
|
|
|
pointer.Resolve = func() Address {
|
|
destination, exists := c.codeLabels[data.Name]
|
|
|
|
if !exists {
|
|
panic("unknown jump label")
|
|
}
|
|
|
|
distance := destination - (pointer.Position + Address(pointer.Size))
|
|
return distance
|
|
}
|
|
|
|
c.codePointers = append(c.codePointers, pointer)
|
|
|
|
case *asm.Register:
|
|
c.code = x86.CallRegister(c.code, data.Register)
|
|
|
|
case *asm.Memory:
|
|
c.code = x86.CallAtMemory(c.code, data.Base, data.Offset)
|
|
}
|
|
}
|