44 lines
922 B
Go
44 lines
922 B
Go
package x64
|
|
|
|
import "git.akyoto.dev/cli/q/src/build/cpu"
|
|
|
|
// MoveRegNum32 moves a 32 bit integer into the given register.
|
|
func MoveRegNum32(code []byte, destination cpu.Register, number uint32) []byte {
|
|
if destination >= 8 {
|
|
code = append(code, REX(0, 0, 0, 1))
|
|
destination -= 8
|
|
}
|
|
|
|
return append(
|
|
code,
|
|
0xb8+byte(destination),
|
|
byte(number),
|
|
byte(number>>8),
|
|
byte(number>>16),
|
|
byte(number>>24),
|
|
)
|
|
}
|
|
|
|
// MoveRegReg64 moves a register value into another register.
|
|
func MoveRegReg64(code []byte, destination cpu.Register, source cpu.Register) []byte {
|
|
r := byte(0) // Extension to the "reg" field in ModRM.
|
|
b := byte(0) // Extension to the "rm" field in ModRM or the SIB base (r8 up to r15 use this).
|
|
|
|
if source >= 8 {
|
|
r = 1
|
|
source -= 8
|
|
}
|
|
|
|
if destination >= 8 {
|
|
b = 1
|
|
destination -= 8
|
|
}
|
|
|
|
return append(
|
|
code,
|
|
REX(1, r, 0, b),
|
|
0x89,
|
|
ModRM(0b11, byte(source), byte(destination)),
|
|
)
|
|
}
|