Improved x64 encoder

This commit is contained in:
2024-07-20 12:49:26 +02:00
parent 6b5dd4c687
commit 7c2e373562
9 changed files with 214 additions and 49 deletions

View File

@ -1,14 +1,18 @@
package x64
import "encoding/binary"
import (
"encoding/binary"
"git.akyoto.dev/cli/q/src/build/cpu"
)
// encodeNum encodes an instruction with up to two registers and a number parameter.
func encodeNum(code []byte, w byte, mod byte, reg byte, rm byte, number int, opCode8 byte, opCode32 byte) []byte {
func encodeNum(code []byte, mod byte, reg cpu.Register, rm cpu.Register, number int, opCode8 byte, opCode32 byte) []byte {
if SizeOf(int64(number)) == 1 {
code = encode(code, w, mod, reg, rm, opCode8)
code = encode(code, mod, reg, rm, 8, opCode8)
return append(code, byte(number))
}
code = encode(code, w, mod, reg, rm, opCode32)
code = encode(code, mod, reg, rm, 8, opCode32)
return binary.LittleEndian.AppendUint32(code, uint32(number))
}