OpCodeAluImm.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. namespace ARMeilleure.Decoders
  3. {
  4. class OpCodeAluImm : OpCodeAlu, IOpCodeAluImm
  5. {
  6. public long Immediate { get; }
  7. public new static OpCode Create(InstDescriptor inst, ulong address, int opCode) => new OpCodeAluImm(inst, address, opCode);
  8. public OpCodeAluImm(InstDescriptor inst, ulong address, int opCode) : base(inst, address, opCode)
  9. {
  10. if (DataOp == DataOp.Arithmetic)
  11. {
  12. Immediate = (opCode >> 10) & 0xfff;
  13. int shift = (opCode >> 22) & 3;
  14. Immediate <<= shift * 12;
  15. }
  16. else if (DataOp == DataOp.Logical)
  17. {
  18. var bm = DecoderHelper.DecodeBitMask(opCode, true);
  19. if (bm.IsUndefined)
  20. {
  21. Instruction = InstDescriptor.Undefined;
  22. return;
  23. }
  24. Immediate = bm.WMask;
  25. }
  26. else
  27. {
  28. throw new ArgumentException(nameof(opCode));
  29. }
  30. }
  31. }
  32. }