Implemented negation
This commit is contained in:
8
src/build/arch/x64/Negate.go
Normal file
8
src/build/arch/x64/Negate.go
Normal file
@ -0,0 +1,8 @@
|
||||
package x64
|
||||
|
||||
import "git.akyoto.dev/cli/q/src/build/cpu"
|
||||
|
||||
// NegateRegister negates the value in the register.
|
||||
func NegateRegister(code []byte, register cpu.Register) []byte {
|
||||
return encode(code, AddressDirect, 0b011, register, 8, 0xF7)
|
||||
}
|
39
src/build/arch/x64/Negate_test.go
Normal file
39
src/build/arch/x64/Negate_test.go
Normal file
@ -0,0 +1,39 @@
|
||||
package x64_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/build/arch/x64"
|
||||
"git.akyoto.dev/cli/q/src/build/cpu"
|
||||
"git.akyoto.dev/go/assert"
|
||||
)
|
||||
|
||||
func TestNegateRegister(t *testing.T) {
|
||||
usagePatterns := []struct {
|
||||
Register cpu.Register
|
||||
Code []byte
|
||||
}{
|
||||
{x64.RAX, []byte{0x48, 0xF7, 0xD8}},
|
||||
{x64.RCX, []byte{0x48, 0xF7, 0xD9}},
|
||||
{x64.RDX, []byte{0x48, 0xF7, 0xDA}},
|
||||
{x64.RBX, []byte{0x48, 0xF7, 0xDB}},
|
||||
{x64.RSP, []byte{0x48, 0xF7, 0xDC}},
|
||||
{x64.RBP, []byte{0x48, 0xF7, 0xDD}},
|
||||
{x64.RSI, []byte{0x48, 0xF7, 0xDE}},
|
||||
{x64.RDI, []byte{0x48, 0xF7, 0xDF}},
|
||||
{x64.R8, []byte{0x49, 0xF7, 0xD8}},
|
||||
{x64.R9, []byte{0x49, 0xF7, 0xD9}},
|
||||
{x64.R10, []byte{0x49, 0xF7, 0xDA}},
|
||||
{x64.R11, []byte{0x49, 0xF7, 0xDB}},
|
||||
{x64.R12, []byte{0x49, 0xF7, 0xDC}},
|
||||
{x64.R13, []byte{0x49, 0xF7, 0xDD}},
|
||||
{x64.R14, []byte{0x49, 0xF7, 0xDE}},
|
||||
{x64.R15, []byte{0x49, 0xF7, 0xDF}},
|
||||
}
|
||||
|
||||
for _, pattern := range usagePatterns {
|
||||
t.Logf("neg %s", pattern.Register)
|
||||
code := x64.NegateRegister(nil, pattern.Register)
|
||||
assert.DeepEqual(t, code, pattern.Code)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user