add alias instruction so that add rX, rX, #Y maps to add rX, #Y

This commit is contained in:
haven1433
2022-10-16 00:52:42 -05:00
parent e0e81612a9
commit afe1dc59b9
4 changed files with 13 additions and 0 deletions

View File

@@ -782,6 +782,7 @@ namespace HavenSoft.HexManiac.Core.Models.Code {
for (int index = 0; index < instructionParts.Count; index++) {
var instruction = instructionParts[index];
if (instruction.Name != name) continue;
if (registerValues.ContainsKey(index) && registerValues[index] != value) return false;
registerValues[index] = value;
}
}

View File

@@ -42,6 +42,7 @@ nv=1111 @ never
0001100 rm rn rd | add rd, rn, rm @ rd = rn + rm
0001101 rm rn rd | sub rd, rn, rm @ rd = rn - rm
0001110000 rn rd | mov rd, rn @ rd = rn
00110 rd # | add rd, rd, # @ rd += # (alais)
0001110 # rn rd | add rd, rn, # @ rd = rn + #
0001111 # rn rd | sub rd, rn, # @ rd = rn - #
00100 rd # | mov rd, # @ rd = #

View File

@@ -375,6 +375,8 @@ namespace HavenSoft.HexManiac.Tests {
[InlineData("add r0, r1, r2", 0b0001100_010_001_000)]
[InlineData("add r0, r1", 0b0001100_001_000_000)]
[InlineData("add r8, r0", 0b1000100_1_0_000_000)]
[InlineData("add r0, r1, #4", 0b0001110_100_001_000)]
[InlineData("add r2, r2, #4", 0b00110_010_00000100)]
[InlineData("lsl r1, r2, #4", 0b00000_00100_010_001)]
[InlineData("lsl r1, #4", 0b00000_00100_001_001)]
[InlineData("bls <000120>", 0b1101_1001_00001110)]

View File

@@ -15,6 +15,9 @@ namespace HavenSoft.HexManiac.Tests {
get => ";".Join(Tool.Contents[0].Content.SplitLines().Select(line => line.Trim()));
set => Tool.Contents[0].Content = value.Replace(";", Environment.NewLine);
}
private string ThumbScript {
set => Tool.Content = value.Replace(";", Environment.NewLine);
}
private string GetContent(int index) => Tool.Contents[index].Content;
private void SetContent(int index, string content) => Tool.Contents[index].Content = content.Replace(";", Environment.NewLine);
@@ -166,5 +169,11 @@ namespace HavenSoft.HexManiac.Tests {
Assert.IsType<PointerRun>(Model.GetNextRun(5));
Model.ResolveConflicts();
}
[Fact]
public void AddWithTwoSameRegisters_AddWithOneRegister_SameCode() {
ThumbScript = "add r3,r3,#6; add r3, #6";
Assert.Equal(Model.ReadMultiByteValue(0, 2), Model.ReadMultiByteValue(2, 2));
}
}
}