Added asmc package

This commit is contained in:
2025-02-06 23:26:10 +01:00
parent cae3092df7
commit 78aee7999b
14 changed files with 464 additions and 386 deletions

31
src/asmc/call.go Normal file
View File

@ -0,0 +1,31 @@
package asmc
import (
"git.akyoto.dev/cli/q/src/asm"
"git.akyoto.dev/cli/q/src/x86"
)
func (c *compiler) call(x asm.Instruction) {
c.code = x86.Call(c.code, 0x00_00_00_00)
size := 4
label := x.Data.(*asm.Label)
pointer := &pointer{
Position: Address(len(c.code) - size),
OpSize: 1,
Size: uint8(size),
}
pointer.Resolve = func() Address {
destination, exists := c.codeLabels[label.Name]
if !exists {
panic("unknown jump label")
}
distance := destination - (pointer.Position + Address(pointer.Size))
return Address(distance)
}
c.codePointers = append(c.codePointers, pointer)
}