Implemented register push and pop

This commit is contained in:
Eduard Urbach 2024-06-25 16:19:47 +02:00
parent 3aedcef9eb
commit e9c46bc3cd
Signed by: eduard
GPG key ID: 49226B848C78F6C8
6 changed files with 128 additions and 6 deletions

View 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 TestPopRegister(t *testing.T) {
usagePatterns := []struct {
Register cpu.Register
Code []byte
}{
{x64.RAX, []byte{0x58}},
{x64.RCX, []byte{0x59}},
{x64.RDX, []byte{0x5A}},
{x64.RBX, []byte{0x5B}},
{x64.RSP, []byte{0x5C}},
{x64.RBP, []byte{0x5D}},
{x64.RSI, []byte{0x5E}},
{x64.RDI, []byte{0x5F}},
{x64.R8, []byte{0x41, 0x58}},
{x64.R9, []byte{0x41, 0x59}},
{x64.R10, []byte{0x41, 0x5A}},
{x64.R11, []byte{0x41, 0x5B}},
{x64.R12, []byte{0x41, 0x5C}},
{x64.R13, []byte{0x41, 0x5D}},
{x64.R14, []byte{0x41, 0x5E}},
{x64.R15, []byte{0x41, 0x5F}},
}
for _, pattern := range usagePatterns {
t.Logf("pop %s", pattern.Register)
code := x64.PopReg(nil, pattern.Register)
assert.DeepEqual(t, code, pattern.Code)
}
}