コード例 #1
0
ファイル: RomItem.cs プロジェクト: pld-lessons/simple_soc
 public RomItem(int address, Opcode opcode)
 {
     Address = address;
     Opcode = opcode;
 }
コード例 #2
0
ファイル: Opcode.cs プロジェクト: pld-lessons/simple_soc
 public object Clone()
 {
     Opcode op = new Opcode(Command, Value, Mask, ApplicableTypes, Pseudo);
     //op.SetLabel(Label);
     //op.SetSourceLine(SourceLine);
     return op;
 }
コード例 #3
0
        private static RomItem[] HandlePseudoInstruction(ref int address, Opcode op)
        {
            ArrayList arl = new ArrayList();
            RomItem ri;

            if (op.Command == Command.org)     // ORiGin
            {
                address = op.Imm16;
                if (!String.IsNullOrEmpty(op.Label))
                    op.SourceLine.SetError("ORG command is not allowed to have a label");
            }
            else if (op.Command == Command.li) // Load Immediate
            {
                ri = new RomItem(address, OpcodeDictionary.Get("movl"));
                ri.Opcode.Register1 = op.Register1;
                if (op.Type == OpcodeType.TwoArg_RegImm16label)
                {
                    ri.Opcode.Imm16label = op.Imm16label;
                    ri.Opcode.Type = OpcodeType.TwoArg_RegImm16label_l;
                }
                else
                {
                    ri.Opcode.Imm8 = op.Imm16 & 0xFF;
                    ri.Opcode.Type = OpcodeType.TwoArg_RegImm8;
                }
                ri.Opcode.Label = op.Label;
                ri.Opcode.SetSourceLine(op.SourceLine);
                arl.Add(ri);
                IncreaseAddress(ref address);

                ri = new RomItem(address, OpcodeDictionary.Get("movh"));
                ri.Opcode.Register1 = op.Register1;
                if (op.Type == OpcodeType.TwoArg_RegImm16label)
                {
                    ri.Opcode.Imm16label = op.Imm16label;
                    ri.Opcode.Type = OpcodeType.TwoArg_RegImm16label_h;
                }
                else
                {
                    ri.Opcode.Imm8 = op.Imm16 >> 8;
                    ri.Opcode.Type = OpcodeType.TwoArg_RegImm8;
                }
                ri.Opcode.SetSourceLine(op.SourceLine);
                arl.Add(ri);
                IncreaseAddress(ref address);
            }
            else if (op.Command == Command.jrl) // JumpRegisterLabel
            {
                ri = new RomItem(address, OpcodeDictionary.Get("movl"));
                ri.Opcode.Register1 = op.Register1;
                //ri.Opcode.Imm8 = op.Imm16 & 0xFF;
                ri.Opcode.Imm16label = op.Imm16label;
                ri.Opcode.Type = OpcodeType.TwoArg_RegImm16label_l;
                ri.Opcode.Label = op.Label;
                ri.Opcode.SetSourceLine(op.SourceLine);
                arl.Add(ri);
                IncreaseAddress(ref address);

                ri = new RomItem(address, OpcodeDictionary.Get("movh"));
                ri.Opcode.Register1 = op.Register1;
                //ri.Opcode.Imm8 = op.Imm16 >> 8;
                ri.Opcode.Imm16label = op.Imm16label;
                ri.Opcode.Type = OpcodeType.TwoArg_RegImm16label_h;
                ri.Opcode.SetSourceLine(op.SourceLine);
                arl.Add(ri);
                IncreaseAddress(ref address);

                ri = new RomItem(address, OpcodeDictionary.Get("jr"));
                ri.Opcode.Register1 = op.Register1;
                ri.Opcode.Type = OpcodeType.OneArg_Reg;
                ri.Opcode.SetSourceLine(op.SourceLine);
                arl.Add(ri);
                IncreaseAddress(ref address);
            }
            else if (op.Command == Command.dw) // DataWord
            {
                ri = new RomItem(address, OpcodeDictionary.Get("dw"));
                ri.Opcode.Data16 = op.Data16;
                ri.Opcode.Type = OpcodeType.OneArg_Data16;
                ri.Opcode.Label = op.Label;
                ri.Opcode.SetSourceLine(op.SourceLine);
                arl.Add(ri);
                IncreaseAddress(ref address);
            }

            return (RomItem[])arl.ToArray(typeof(RomItem));
        }