Permalink
Browse files

fixed bugs found while testing, added input for a label (symlink) to …

…be used as an opcode
  • Loading branch information...
1 parent 0b130b2 commit 957e41d1a8248282c86d570768ff01af5ec3d33e @danpalmer committed Apr 18, 2010
View
BIN .DS_Store
Binary file not shown.
View
Binary file not shown.
@@ -160,6 +160,7 @@
<None Include="Assembly Simulator_TemporaryKey.pfx" />
<EmbeddedResource Include="InstructionList.dat">
</EmbeddedResource>
+ <None Include="Properties\app.manifest" />
<None Include="README.txt" />
</ItemGroup>
<ItemGroup>
@@ -194,7 +195,7 @@
-->
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_UpdateFileVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.DayStamp" BuildVersion_UpdateAssemblyVersion="True" />
+ <UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.DayStamp" BuildVersion_UpdateFileVersion="True" />
</VisualStudio>
</ProjectExtensions>
</Project>
View
24 Assembly Simulator/CPU.cs 100644 → 100755
@@ -234,12 +234,13 @@ private void ST(string label, int intOperand, string operand)
}
}
- error(null, "Could not find symbolic link in array, "
+ // Code should never reach this location
+ error(null, "Could not find the label in array, "
+ "please contact the publisher of this program for assistance");
}
else
{
- parent.setValueForRAMIndex(Convert.ToInt32(operand), accumulator);
+ parent.setValueForRAMIndex(Convert.ToInt32(hexToInt(operand)), accumulator);
Debug.WriteLine("Stored accumulator in memory location");
}
}
@@ -299,7 +300,7 @@ private void GETINT(string label, int operand)
int y = Convert.ToInt32(x);
// Validation done here because the input window is for letters and numbers
- if (y > 127 || y < -127)
+ if (y > 255 || y < 0)
error(null, "Integer is not within the correct bounds");
else
{
@@ -370,10 +371,19 @@ private void DEFB(string label, int operand)
// Jump to operand label
private void JP(string label, string operand)
{
- if (operand == "" || operand == null) {
- // Change the next instruction to be executed by getting the label to jump to
- this.programCounter = (parent.programInstructionIndexForLabel(operand) -1).ToString();
- }
+ if (operand != "" && operand != null)
+ {
+ // Change the next instruction to be executed by getting the label to jump to
+ this.programCounter = (parent.programInstructionIndexForLabel(operand) - 1).ToString();
+ if (this.programCounter == (-2).ToString())
+ {
+ error("Bad Jump Instruction", "The label you tried to jump to does not exist.");
+ }
+ }
+ else
+ {
+ error("Bad Jump Instruction", "The Jump instruction requires an operand of the label to jump to.");
+ }
}
// Jump to operand label if greater: z=0 and ns=0
View
@@ -87,7 +87,7 @@ private void errorFlash()
base.ForeColor = Color.White;
// Create a timer set to call endErrorFlash in 0.1s and start it
Timer timer = new Timer();
- timer.Interval = 100;
+ timer.Interval = 2000;
timer.Tick += new System.EventHandler(this.endErrorFlash);
timer.Start();
}
@@ -7,20 +7,23 @@
</detail>
<OPCODE>LD</OPCODE>
<colour>1</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Store</name>
<detail>Stores the value of the accumulator to a memory address. Takes the OPERAND of either a direct address or a symbolic address.
</detail>
<OPCODE>ST</OPCODE>
<colour>1</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Define Byte</name>
<detail>This defines a label and a variable. The variable will be stored in the first available memory location.
</detail>
<OPCODE>DEFB</OPCODE>
<colour>1</colour>
+ <allowlabel>no</allowlabel>
</instruction>
<!-- MATHS FUNCTIONS -->
<instruction>
@@ -29,13 +32,15 @@
</detail>
<OPCODE>ADD</OPCODE>
<colour>2</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Subtract</name>
<detail>Subtracts either a number of the contents of a memory location from the accumulator. Takes the OPERAND of a immediate address, direct address or symbolic address.
</detail>
<OPCODE>SUB</OPCODE>
<colour>2</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Multiply</name>
@@ -45,20 +50,23 @@
</detail>
<OPCODE>MUL</OPCODE>
<colour>2</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Divide</name>
<detail>Divides the contents of the accumulator by either the contents of a memory location or a number. Takes the OPERAND of a immediate address, direct address or symbolic address.
</detail>
<OPCODE>DIV</OPCODE>
<colour>2</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>And</name>
<detail>Performs an AND operation on the contents of the accumulator and a given number or memory location. Takes the OPERAND of a immediate address, direct address or symbolic address.
</detail>
<OPCODE>AND</OPCODE>
<colour>2</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Or</name>
@@ -68,6 +76,7 @@
</detail>
<OPCODE>OR</OPCODE>
<colour>2</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<!-- COMPARISON FUNCTIONS -->
<instruction>
@@ -76,6 +85,7 @@
</detail>
<OPCODE>CMP</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump</name>
@@ -85,48 +95,55 @@
</detail>
<OPCODE>JP</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump if Equal</name>
<detail>Jumps if the zero flag is set and therefore jumps when the accumulator is equal to what it was compared with in the CMP command. Takes the OPERAND of a label to jump to in the program.
</detail>
<OPCODE>JE</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump if Greater</name>
<detail>Jumps if the zero flag is not 1 and the sign flag is the same as the overflow. Takes the OPERAND of a label to jump to in the program.
</detail>
<OPCODE>JG</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump if Less</name>
<detail>Jumps if the zero flag is not 1 and the sign flag is not the same as the overflow. Takes the OPERAND of a label to jump to in the program.
</detail>
<OPCODE>JL</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump if Greater than or Equal</name>
<detail>Jumps if the zero flag is 1 or the sign flag is not the same as the overflow. Takes the OPERAND of a label to jump to in the program.
</detail>
<OPCODE>JGE</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump if Less or Equal</name>
<detail>Jumps if the zero flag is 1 or the sign flag is not the same as the overflow. Takes the OPERAND of a label to jump to in the program.
</detail>
<OPCODE>JLE</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump if Not Equal</name>
<detail>Jumps if the the zero flag is 0. Takes the OPERAND of a label to jump to in the program.
</detail>
<OPCODE>JNE</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<!-- OTHER STUFF -->
<instruction>
@@ -135,26 +152,30 @@
</detail>
<OPCODE>GETCHAR</OPCODE>
<colour>4</colour>
+ <allowlabel>no</allowlabel>
</instruction>
<instruction>
<name>Get Integer</name>
<detail>Gets an integer and puts it in the accumulator.
</detail>
<OPCODE>GETINT</OPCODE>
<colour>4</colour>
+ <allowlabel>no</allowlabel>
</instruction>
<instruction>
<name>Put Character</name>
<detail>Outputs the character for the ASCII code currently stored in the accumulator.
</detail>
<OPCODE>PUTCHAR</OPCODE>
<colour>4</colour>
+ <allowlabel>no</allowlabel>
</instruction>
<instruction>
<name>Put Integer</name>
<detail>Outputs the integer currently in the accumulator.
</detail>
<OPCODE>PUTINT</OPCODE>
<colour>4</colour>
+ <allowlabel>no</allowlabel>
</instruction>
</List>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -13,9 +13,10 @@ namespace Assembly_Simulator
public partial class InstructionView : UserControl
{
private Main parent;
+ private bool validatedInput;
// Initialisation Code
- public InstructionView(string name, string detail, string OPCODE, int colour, Main p)
+ public InstructionView(string name, string detail, string OPCODE, int colour, string vI, Main p)
{
InitializeComponent();
labelName.Text = name;
@@ -44,7 +45,14 @@ public InstructionView(string name, string detail, string OPCODE, int colour, Ma
changeColour(Color.FromName("GradientInactiveCaption"));
break;
}
-
+
+ if (vI == "yes")
+ {
+ validatedInput = true;
+ } else {
+ validatedInput = false;
+ }
+
parent = p;
// Set other values
@@ -107,9 +115,15 @@ private void addInstruction_Click(object sender, EventArgs e)
// TODO: get this to work with tabbing in to the box rather than clicking on it.
private void textBoxOPERAND_Click(object sender, EventArgs e)
{
- Control c = (Control)sender;
- ((TextBox)sender).Text = parent.getValidatedInput(c);
- this.addInstruction.Select();
+ if (validatedInput) {
+ Control c = (Control)sender;
+ ((TextBox)sender).Text = parent.getValidatedInput(c, true);
+ this.addInstruction.Select();
+ } else {
+ Control c = (Control)sender;
+ ((TextBox)sender).Text = parent.getValidatedInput(c, false);
+ this.addInstruction.Select();
+ }
}
}
}
View
@@ -39,14 +39,15 @@ public Main()
string[,] opcodes = parser.GetInstructions();
- for (int i = 0; i < (opcodes.Length / 4); i++)
+ for (int i = 0; i < (opcodes.Length / 5); i++)
{
InstructionView newInstruction
= new InstructionView(
opcodes[i, 0],
opcodes[i, 1],
opcodes[i, 2],
Convert.ToInt32(opcodes[i, 3]),
+ opcodes[i, 4],
this);
instructionFlowPanel.Controls.Add(newInstruction);
}
@@ -328,7 +329,7 @@ private void newButton_Click(object sender, EventArgs e)
RAM_OutOfDate = true;
processor.reset("all");
updateProcessorValues();
- mainFormTabs.SelectTab(tabExecute);
+ mainFormTabs.SelectTab(tabWrite);
updateCPUDiagramValues();
}
}
@@ -644,8 +645,17 @@ private void saveButton_Click(object sender, EventArgs e)
{
StreamWriter s;
s = File.CreateText(save.FileName);
+ bool error = false;
foreach (ProgramInstruction i in instructions)
{
+ if (i.label.Length > 20)
+ {
+ i.label = i.label.Substring(0, 20);
+ if (!error)
+ {
+ MessageBox.Show("One or more of your labels has exceeded the maximum length of 20 characters. To continue saving it has been shortened automatically.", "Error Saving File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+ }
+ }
s.WriteLine(i.saveableInstruction());
}
s.Close();
@@ -719,10 +729,14 @@ private DialogResult new_program()
#endregion
- internal string getValidatedInput(Control control)
+ internal string getValidatedInput(Control control, bool allowLabel)
{
ValidationWindow v = new ValidationWindow();
TextBox x = (TextBox)control;
+ if (allowLabel)
+ {
+ v.allowLabel();
+ }
this.TopMost = true;
if (v.ShowDialog(this) == DialogResult.OK)
@@ -737,6 +751,11 @@ internal string getValidatedInput(Control control)
this.TopMost = false;
return v.rah.Text.Insert(0, "#");
}
+ if (v.textboxLabel.Text != "")
+ {
+ this.TopMost = false;
+ return v.textboxLabel.Text;
+ }
else
{
// Fail
Oops, something went wrong.

0 comments on commit 957e41d

Please sign in to comment.