Implemented move with sign extension
This commit is contained in:
@ -9,12 +9,17 @@ import (
|
||||
// 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 w == 0 && number < 0 {
|
||||
return MoveRegisterNumber32(code, destination, number)
|
||||
}
|
||||
|
||||
b := byte(0)
|
||||
|
||||
if destination > 0b111 {
|
||||
b = 1
|
||||
destination &= 0b111
|
||||
@ -33,6 +38,21 @@ func MoveRegisterNumber(code []byte, destination cpu.Register, number int) []byt
|
||||
}
|
||||
}
|
||||
|
||||
// MoveRegisterNumber32 moves an integer into the given register and sign-extends the register.
|
||||
func MoveRegisterNumber32(code []byte, destination cpu.Register, number int) []byte {
|
||||
b := byte(0)
|
||||
|
||||
if destination > 0b111 {
|
||||
b = 1
|
||||
destination &= 0b111
|
||||
}
|
||||
|
||||
code = append(code, REX(1, 0, 0, b))
|
||||
code = append(code, 0xC7)
|
||||
code = append(code, ModRM(AddressDirect, 0, byte(destination)))
|
||||
return binary.LittleEndian.AppendUint32(code, uint32(number))
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
Reference in New Issue
Block a user