50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package asmc
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.urbach.dev/cli/q/src/asm"
|
|
"git.urbach.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)
|
|
}
|
|
|
|
label := c.assembler.Param.Label[x.Index]
|
|
size := 1
|
|
|
|
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(fmt.Sprintf("unknown jump label %s", label.Name))
|
|
}
|
|
|
|
distance := destination - (pointer.Position + Address(pointer.Size))
|
|
return distance
|
|
}
|
|
|
|
c.codePointers = append(c.codePointers, pointer)
|
|
}
|