示例#1
0
 public SubleqInstruction(String sourceLine, int sourceLineNumber, int sourceAddress, String sourceLabel, Address operand_a, Address operand_b, Address operand_c, bool autoBranchNext)
     : base(sourceLine, sourceLineNumber, sourceAddress, sourceLabel, operand_c, autoBranchNext)
 {
     this.Operand_a = operand_a;
     this.Operand_b = operand_b;
     this.Operand_c = operand_c;
 }
示例#2
0
 public BranchingInstruction(String sourceLine, int sourceLineNumber, int sourceAddress, String sourceLabel, Address operand_branch, bool autoBranchNext)
     : base(sourceLine, sourceLineNumber, sourceAddress, sourceLabel)
 {
     this.AutoBranchNext = autoBranchNext;
     this.BranchAddress = operand_branch;
 }
示例#3
0
 public BranchingInstruction(String sourceLine, int sourceLineNumber, int sourceAddress, Address operand_branch)
     : this(sourceLine, sourceLineNumber, sourceAddress, String.Empty, operand_branch, false)
 {
 }
示例#4
0
 public SubleqInstruction(String sourceLine, int sourceLineNumber, int sourceAddress, String sourceLabel, Address operand_a, Address operand_b, Address operand_c)
     : this(sourceLine, sourceLineNumber, sourceAddress, sourceLabel, operand_a, operand_b, operand_c, false)
 {
 }
示例#5
0
 public SubleqInstruction(String sourceLine, int sourceLineNumber, int sourceAddress, String sourceLabel, Address operand_a, Address operand_b, bool autoBranchNext)
     : this(sourceLine, sourceLineNumber, sourceAddress, sourceLabel, operand_a, operand_b, null, autoBranchNext)
 {
 }
示例#6
0
 private AddressableMemoryInstruction MapAddressedOperands(Dictionary<string, AddressableInstruction> labeledInstructionDictionary, Address operand_Value)
 {
     if (operand_Value.IsLabelledAddress)
     {
         if (labeledInstructionDictionary.ContainsKey(operand_Value.AddressLabel))
         {
             return labeledInstructionDictionary[operand_Value.AddressLabel] as AddressableMemoryInstruction;
         }
         else
         {
             //TODO: Handle source syntax errors.
             return null;
         }
     }
     else
     {
         return null;
     }
 }
示例#7
0
        public Instruction GenerateInstruction(String sourceLine, int sourceLineNumber, int sourceAddress)
        {
            String trimmedSourceLine = sourceLine.Trim().RemoveMultipleSpaces();

            if (!String.IsNullOrEmpty(trimmedSourceLine))
            {
                if (trimmedSourceLine.StartsWith("//"))
                {
                    // This source line is a comment.
                    return new CommentInstruction(trimmedSourceLine, sourceLineNumber);
                }
                else
                {
                    String[] instructionData = trimmedSourceLine.Split(' ');

                    if (instructionData[0].EndsWith(LexicalSymbols.Label))
                    {
                        String sourceLabel = instructionData[0].Replace(LexicalSymbols.Label, String.Empty);
                        if (instructionData.Length == 4)
                        {
                            // Labeled subleq instruction.
                            Address operand_a = new Address(instructionData[1]);
                            Address operand_b = new Address(instructionData[2]);
                            Address operand_c =new Address( instructionData[3]);
                            return new SubleqInstruction(trimmedSourceLine, sourceLineNumber, sourceAddress, sourceLabel, operand_a, operand_b, operand_c);
                        }
                        if (instructionData.Length == 3)
                        {
                            // Labeled subleq instruction with auto branch next.
                            Address operand_a = new Address( instructionData[1]);
                            Address operand_b = new Address( instructionData[2]);
                            return new SubleqInstruction(trimmedSourceLine, sourceLineNumber, sourceAddress, sourceLabel, operand_a, operand_b, true);
                        }
                        else if (instructionData.Length == 2)
                        {
                            // Labeled memory value.
                            String value = instructionData[1];
                            if (value.StartsWith(LexicalSymbols.LabelAddress))
                            {
                                Address valueAddress = new Address(value);
                                return new AddressableMemoryInstruction(trimmedSourceLine, sourceLineNumber, sourceAddress, sourceLabel, valueAddress);
                            }
                            else
                            {
                                return new AddressableMemoryInstruction(trimmedSourceLine, sourceLineNumber, sourceAddress, sourceLabel, value);
                            }
                        }
                        else
                        {
                            //TODO: Need to handle invalid source code.
                            return null;
                        }
                    }
                    else
                    {
                        if (instructionData.Length == 3)
                        {
                            // Unlabeled subleq instruction.
                            Address operand_a = new Address( instructionData[0]);
                            Address operand_b = new Address( instructionData[1]);
                            Address operand_c = new Address( instructionData[2]);
                            return new SubleqInstruction(trimmedSourceLine, sourceLineNumber, sourceAddress, operand_a, operand_b, operand_c);
                        }
                        if (instructionData.Length == 2)
                        {
                            // Unlabeled subleq instruction with auto branch next.
                            Address operand_a = new Address( instructionData[0]);
                            Address operand_b = new Address( instructionData[1]);
                            return new SubleqInstruction(trimmedSourceLine, sourceLineNumber, sourceAddress, operand_a, operand_b, true);
                        }
                        else
                        {
                            //TODO: Need to handle invalid source code.
                            return null;
                        }
                    }
                }
            }
            else
            {
                return null;
            }
        }
 internal void MapMemoryValue(Dictionary<int, AddressableInstruction> instructionDictionary, Dictionary<string, AddressableInstruction> labeledInstructionDictionary)
 {
     if (IsValueAddress)
     {
         if (this.ValueAddress.IsLabelledAddress)
         {
             // If the branch is a label, resolve the labeled instruction...
             AddressableInstruction valueLocation = labeledInstructionDictionary[this.ValueAddress.AddressLabel] as AddressableInstruction;
             this.ValueAddress = valueLocation.Address;
         }
         else if (this.ValueAddress.SourceAddress != -1)
         {
             // ...Otherwise, resolve the destination from the branch source address.
             AddressableInstruction valueLocation = instructionDictionary[this.ValueAddress.SourceAddress] as AddressableInstruction;
             this.ValueAddress = valueLocation.Address;
         }
     }
 }
 public AddressableMemoryInstruction(String sourceLine, int sourceLineNumber, int sourceAddress, String sourceLabel, Address valueAddress)
     : base(sourceLine, sourceLineNumber, sourceAddress, sourceLabel)
 {
     this.InitialValue = String.Empty;
     this.ValueAddress = valueAddress;
 }