40 lines
910 B
Go
40 lines
910 B
Go
package x64_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.akyoto.dev/cli/q/src/arch/x64"
|
|
"git.akyoto.dev/cli/q/src/cpu"
|
|
"git.akyoto.dev/go/assert"
|
|
)
|
|
|
|
func TestPushRegister(t *testing.T) {
|
|
usagePatterns := []struct {
|
|
Register cpu.Register
|
|
Code []byte
|
|
}{
|
|
{x64.RAX, []byte{0x50}},
|
|
{x64.RCX, []byte{0x51}},
|
|
{x64.RDX, []byte{0x52}},
|
|
{x64.RBX, []byte{0x53}},
|
|
{x64.RSP, []byte{0x54}},
|
|
{x64.RBP, []byte{0x55}},
|
|
{x64.RSI, []byte{0x56}},
|
|
{x64.RDI, []byte{0x57}},
|
|
{x64.R8, []byte{0x41, 0x50}},
|
|
{x64.R9, []byte{0x41, 0x51}},
|
|
{x64.R10, []byte{0x41, 0x52}},
|
|
{x64.R11, []byte{0x41, 0x53}},
|
|
{x64.R12, []byte{0x41, 0x54}},
|
|
{x64.R13, []byte{0x41, 0x55}},
|
|
{x64.R14, []byte{0x41, 0x56}},
|
|
{x64.R15, []byte{0x41, 0x57}},
|
|
}
|
|
|
|
for _, pattern := range usagePatterns {
|
|
t.Logf("push %s", pattern.Register)
|
|
code := x64.PushRegister(nil, pattern.Register)
|
|
assert.DeepEqual(t, code, pattern.Code)
|
|
}
|
|
}
|