aboutsummaryrefslogtreecommitdiff
path: root/src/ARMeilleure/Decoders/OpCodeT16MemMult.cs
blob: 92b027a6edd5a9b5999626bcfbf2dddb883f3901 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using ARMeilleure.Instructions;
using System;
using System.Numerics;

namespace ARMeilleure.Decoders
{
    class OpCodeT16MemMult : OpCodeT16, IOpCode32MemMult
    {
        public int Rn { get; }
        public int RegisterMask { get; }
        public int PostOffset { get; }
        public bool IsLoad { get; }
        public int Offset { get; }

        public new static OpCode Create(InstDescriptor inst, ulong address, int opCode) => new OpCodeT16MemMult(inst, address, opCode);

        public OpCodeT16MemMult(InstDescriptor inst, ulong address, int opCode) : base(inst, address, opCode)
        {
            RegisterMask = opCode & 0xff;
            Rn = (opCode >> 8) & 7;

            int regCount = BitOperations.PopCount((uint)RegisterMask);

            Offset = 0;
            PostOffset = 4 * regCount;
            IsLoad = inst.Name switch
            {
                InstName.Ldm => true,
                InstName.Stm => false,
                _ => throw new InvalidOperationException(),
            };
        }
    }
}