Added asmc package
This commit is contained in:
47
src/asmc/jump.go
Normal file
47
src/asmc/jump.go
Normal file
@ -0,0 +1,47 @@
|
||||
package asmc
|
||||
|
||||
import (
|
||||
"git.akyoto.dev/cli/q/src/asm"
|
||||
"git.akyoto.dev/cli/q/src/x86"
|
||||
)
|
||||
|
||||
func (c *compiler) jump(x asm.Instruction) {
|
||||
switch x.Mnemonic {
|
||||
case asm.JE:
|
||||
c.code = x86.Jump8IfEqual(c.code, 0x00)
|
||||
case asm.JNE:
|
||||
c.code = x86.Jump8IfNotEqual(c.code, 0x00)
|
||||
case asm.JG:
|
||||
c.code = x86.Jump8IfGreater(c.code, 0x00)
|
||||
case asm.JGE:
|
||||
c.code = x86.Jump8IfGreaterOrEqual(c.code, 0x00)
|
||||
case asm.JL:
|
||||
c.code = x86.Jump8IfLess(c.code, 0x00)
|
||||
case asm.JLE:
|
||||
c.code = x86.Jump8IfLessOrEqual(c.code, 0x00)
|
||||
case asm.JUMP:
|
||||
c.code = x86.Jump8(c.code, 0x00)
|
||||
}
|
||||
|
||||
size := 1
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user