diff --git a/src/arm/Compare_test.go b/src/arm/Compare_test.go index 16cecdd..4ed047c 100644 --- a/src/arm/Compare_test.go +++ b/src/arm/Compare_test.go @@ -27,3 +27,19 @@ func TestCompareRegisterNumber(t *testing.T) { assert.DeepEqual(t, code, pattern.Code) } } + +func TestCompareRegisterRegister(t *testing.T) { + usagePatterns := []struct { + Left cpu.Register + Right cpu.Register + Code uint32 + }{ + {arm.X0, arm.X1, 0xEB01001F}, + } + + for _, pattern := range usagePatterns { + t.Logf("cmp %s, %s", pattern.Left, pattern.Right) + code := arm.CompareRegisterRegister(pattern.Left, pattern.Right) + assert.DeepEqual(t, code, pattern.Code) + } +} diff --git a/src/arm/Load.go b/src/arm/Load.go index afbd176..0b4f6de 100644 --- a/src/arm/Load.go +++ b/src/arm/Load.go @@ -13,9 +13,7 @@ func LoadRegister(destination cpu.Register, base cpu.Register, offset int, lengt return 0b01111<<27 | common case 4: return 0b10111<<27 | common - case 8: + default: return 0b11111<<27 | common } - - panic("invalid length") } diff --git a/src/arm/Store.go b/src/arm/Store.go index ceeb839..65c246b 100644 --- a/src/arm/Store.go +++ b/src/arm/Store.go @@ -15,9 +15,7 @@ func StoreRegister(source cpu.Register, base cpu.Register, offset int, length by return 0b01111<<27 | common case 4: return 0b10111<<27 | common - case 8: + default: return 0b11111<<27 | common } - - panic("invalid length") } diff --git a/src/arm/arm_test.go b/src/arm/arm_test.go index b81e610..9a6693f 100644 --- a/src/arm/arm_test.go +++ b/src/arm/arm_test.go @@ -27,4 +27,12 @@ func TestNotEncodable(t *testing.T) { assert.False(t, encodable) _, encodable = arm.XorRegisterNumber(arm.X0, arm.X0, -1) assert.False(t, encodable) + _, encodable = arm.AddRegisterNumber(arm.X0, arm.X0, 0xFFFF) + assert.False(t, encodable) + _, encodable = arm.AddRegisterNumber(arm.X0, arm.X0, 0xF0000000) + assert.False(t, encodable) + _, encodable = arm.SubRegisterNumber(arm.X0, arm.X0, 0xFFFF) + assert.False(t, encodable) + _, encodable = arm.SubRegisterNumber(arm.X0, arm.X0, 0xF0000000) + assert.False(t, encodable) }