about summary refs log tree commit diff stats
path: root/test/arch/mep/ir/test_logical.py
blob: e78b548877fd8a306e7f342978f1f165baeebc65 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Toshiba MeP-c4 - Logical instructions unit tests
# Guillaume Valadon <guillaume@valadon.net>

from ut_helpers_ir import exec_instruction

from miasm2.expression.expression import ExprId, ExprInt, ExprCond, ExprOp


class TestLogical(object):

    def test_or(self):
        """Test OR execution"""

        # OR Rn, Rm
        exec_instruction("OR R1, R2",
                         [(ExprId("R1", 32), ExprInt(1, 32)), (ExprId("R2", 32), ExprInt(1, 32))],
                         [(ExprId("R1", 32), ExprInt(1, 32))])

    def test_or3(self):
        """Test OR3 execution"""

        # OR3 Rn,Rm,imm16
        exec_instruction("OR3 R1, R2, 1",
                         [(ExprId("R2", 32), ExprInt(1, 32))],
                         [(ExprId("R1", 32), ExprInt(1, 32))])

    def test_and(self):
        """Test AND  execution"""

        # AND Rn, Rm
        exec_instruction("AND R1, R2",
                         [(ExprId("R1", 32), ExprInt(1, 32)), (ExprId("R2", 32), ExprInt(0, 32))],
                         [(ExprId("R1", 32), ExprInt(0, 32))])

    def test_and3(self):
        """Test AND3 execution"""

        # AND3 Rn,Rm,imm16
        exec_instruction("AND3 R1, R2, 0",
                         [(ExprId("R2", 32), ExprInt(1, 32))],
                         [(ExprId("R1", 32), ExprInt(0, 32))])

    def test_xor(self):
        """Test XOR execution"""

        # XOR Rn, Rm
        exec_instruction("XOR R1, R2",
                         [(ExprId("R1", 32), ExprInt(1, 32)), (ExprId("R2", 32), ExprInt(0, 32))],
                         [(ExprId("R1", 32), ExprInt(1, 32))])

    def test_xor3(self):
        """Test XOR3 execution"""

        # XOR3 Rn,Rm,imm16
        exec_instruction("XOR3 R1, R2, 1",
                         [(ExprId("R2", 32), ExprInt(0, 32))],
                         [(ExprId("R1", 32), ExprInt(1, 32))])

    def test_nor(self):
        """Test NOR execution"""

        # NOR Rn, Rm
        exec_instruction("NOR R1, R2",
                         [(ExprId("R1", 32), ExprInt(1, 32)), (ExprId("R2", 32), ExprInt(0, 32))],
                         [(ExprId("R1", 32), ExprInt(0xFFFFFFFE, 32))])