Implemented array storage
This commit is contained in:
@ -3,6 +3,6 @@ package x64
|
||||
import "git.akyoto.dev/cli/q/src/build/cpu"
|
||||
|
||||
// LoadRegister loads from memory into a register.
|
||||
func LoadRegister(code []byte, destination cpu.Register, offset byte, numBytes byte, source cpu.Register) []byte {
|
||||
return memoryAccess(code, 0x8A, 0x8B, source, offset, numBytes, destination)
|
||||
func LoadRegister(code []byte, destination cpu.Register, offset byte, length byte, source cpu.Register) []byte {
|
||||
return memoryAccess(code, 0x8A, 0x8B, source, offset, length, destination)
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ func TestLoadRegister(t *testing.T) {
|
||||
Destination cpu.Register
|
||||
Source cpu.Register
|
||||
Offset byte
|
||||
NumBytes byte
|
||||
Length byte
|
||||
Code []byte
|
||||
}{
|
||||
// No offset
|
||||
@ -150,8 +150,8 @@ func TestLoadRegister(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, pattern := range usagePatterns {
|
||||
t.Logf("load %dB %s, [%s+%d]", pattern.NumBytes, pattern.Destination, pattern.Source, pattern.Offset)
|
||||
code := x64.LoadRegister(nil, pattern.Destination, pattern.Offset, pattern.NumBytes, pattern.Source)
|
||||
t.Logf("load %dB %s, [%s+%d]", pattern.Length, pattern.Destination, pattern.Source, pattern.Offset)
|
||||
code := x64.LoadRegister(nil, pattern.Destination, pattern.Offset, pattern.Length, pattern.Source)
|
||||
assert.DeepEqual(t, code, pattern.Code)
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ import (
|
||||
)
|
||||
|
||||
// StoreNumber stores a number into the memory address included in the given register.
|
||||
func StoreNumber(code []byte, register cpu.Register, offset byte, numBytes byte, number int) []byte {
|
||||
code = memoryAccess(code, 0xC6, 0xC7, register, offset, numBytes, 0b000)
|
||||
func StoreNumber(code []byte, register cpu.Register, offset byte, length byte, number int) []byte {
|
||||
code = memoryAccess(code, 0xC6, 0xC7, register, offset, length, 0b000)
|
||||
|
||||
switch numBytes {
|
||||
switch length {
|
||||
case 8, 4:
|
||||
return binary.LittleEndian.AppendUint32(code, uint32(number))
|
||||
|
||||
@ -22,6 +22,6 @@ func StoreNumber(code []byte, register cpu.Register, offset byte, numBytes byte,
|
||||
}
|
||||
|
||||
// StoreRegister stores the contents of the `source` register into the memory address included in the given register.
|
||||
func StoreRegister(code []byte, register cpu.Register, offset byte, numBytes byte, source cpu.Register) []byte {
|
||||
return memoryAccess(code, 0x88, 0x89, register, offset, numBytes, source)
|
||||
func StoreRegister(code []byte, register cpu.Register, offset byte, length byte, source cpu.Register) []byte {
|
||||
return memoryAccess(code, 0x88, 0x89, register, offset, length, source)
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ func TestStoreNumber(t *testing.T) {
|
||||
usagePatterns := []struct {
|
||||
Register cpu.Register
|
||||
Offset byte
|
||||
NumBytes byte
|
||||
Length byte
|
||||
Number int
|
||||
Code []byte
|
||||
}{
|
||||
@ -150,8 +150,8 @@ func TestStoreNumber(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, pattern := range usagePatterns {
|
||||
t.Logf("store %dB [%s+%d], %d", pattern.NumBytes, pattern.Register, pattern.Offset, pattern.Number)
|
||||
code := x64.StoreNumber(nil, pattern.Register, pattern.Offset, pattern.NumBytes, pattern.Number)
|
||||
t.Logf("store %dB [%s+%d], %d", pattern.Length, pattern.Register, pattern.Offset, pattern.Number)
|
||||
code := x64.StoreNumber(nil, pattern.Register, pattern.Offset, pattern.Length, pattern.Number)
|
||||
assert.DeepEqual(t, code, pattern.Code)
|
||||
}
|
||||
}
|
||||
@ -160,7 +160,7 @@ func TestStoreRegister(t *testing.T) {
|
||||
usagePatterns := []struct {
|
||||
RegisterTo cpu.Register
|
||||
Offset byte
|
||||
NumBytes byte
|
||||
Length byte
|
||||
RegisterFrom cpu.Register
|
||||
Code []byte
|
||||
}{
|
||||
@ -298,8 +298,8 @@ func TestStoreRegister(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, pattern := range usagePatterns {
|
||||
t.Logf("store %dB [%s+%d], %s", pattern.NumBytes, pattern.RegisterTo, pattern.Offset, pattern.RegisterFrom)
|
||||
code := x64.StoreRegister(nil, pattern.RegisterTo, pattern.Offset, pattern.NumBytes, pattern.RegisterFrom)
|
||||
t.Logf("store %dB [%s+%d], %s", pattern.Length, pattern.RegisterTo, pattern.Offset, pattern.RegisterFrom)
|
||||
code := x64.StoreRegister(nil, pattern.RegisterTo, pattern.Offset, pattern.Length, pattern.RegisterFrom)
|
||||
assert.DeepEqual(t, code, pattern.Code)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user