예제 #1
0
 public RomItem(int address, Opcode opcode)
 {
     Address = address;
     Opcode = opcode;
 }
예제 #2
0
 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));
        }