Added basic support for arm64
This commit is contained in:
29
src/arm/Move.go
Normal file
29
src/arm/Move.go
Normal file
@ -0,0 +1,29 @@
|
||||
package arm
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
|
||||
"git.urbach.dev/cli/q/src/cpu"
|
||||
)
|
||||
|
||||
// MoveRegisterNumber moves an integer into the given register.
|
||||
func MoveRegisterNumber(code []byte, destination cpu.Register, number int) []byte {
|
||||
return MoveZero(code, destination, 0, uint16(number))
|
||||
}
|
||||
|
||||
// MoveKeep moves a 16-bit integer into the given register and keeps all other bits.
|
||||
func MoveKeep(code []byte, destination cpu.Register, halfword int, number uint16) []byte {
|
||||
x := mov(0b11, halfword, number, destination)
|
||||
return binary.LittleEndian.AppendUint32(code, x)
|
||||
}
|
||||
|
||||
// MoveZero moves a 16-bit integer into the given register and clears all other bits to zero.
|
||||
func MoveZero(code []byte, destination cpu.Register, halfword int, number uint16) []byte {
|
||||
x := mov(0b10, halfword, number, destination)
|
||||
return binary.LittleEndian.AppendUint32(code, x)
|
||||
}
|
||||
|
||||
// mov encodes a generic move instruction.
|
||||
func mov(opCode uint32, halfword int, number uint16, destination cpu.Register) uint32 {
|
||||
return (1 << 31) | (opCode << 29) | (0b100101 << 23) | uint32(halfword<<21) | uint32(number<<5) | uint32(destination)
|
||||
}
|
Reference in New Issue
Block a user