Implemented 64-bit move

This commit is contained in:
2024-07-26 16:19:13 +02:00
parent 123738f88c
commit bf80551a15
8 changed files with 62 additions and 29 deletions

View File

@ -6,18 +6,34 @@ import (
"git.akyoto.dev/cli/q/src/build/cpu"
)
// MoveRegisterNumber32 moves a 32 bit integer into the given register.
func MoveRegisterNumber32(code []byte, destination cpu.Register, number uint32) []byte {
// MoveRegisterNumber moves an integer into the given register.
func MoveRegisterNumber(code []byte, destination cpu.Register, number int) []byte {
w := byte(0)
b := byte(0)
if SizeOf(int64(number)) == 8 {
w = 1
}
if destination > 0b111 {
code = append(code, REX(0, 0, 0, 1))
b = 1
destination &= 0b111
}
code = append(code, 0xb8+byte(destination))
return binary.LittleEndian.AppendUint32(code, number)
if w != 0 || b != 0 {
code = append(code, REX(w, 0, 0, b))
}
code = append(code, 0xB8+byte(destination))
if w == 1 {
return binary.LittleEndian.AppendUint64(code, uint64(number))
} else {
return binary.LittleEndian.AppendUint32(code, uint32(number))
}
}
// MoveRegisterRegister64 moves a register value into another register.
func MoveRegisterRegister64(code []byte, destination cpu.Register, source cpu.Register) []byte {
// MoveRegisterRegister moves a register value into another register.
func MoveRegisterRegister(code []byte, destination cpu.Register, source cpu.Register) []byte {
return encode(code, AddressDirect, source, destination, 8, 0x89)
}