OpenCores
URL https://opencores.org/ocsvn/s80186/s80186/trunk

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [instructions/] [TestXchg.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
#include <gtest/gtest.h>
19
 
20
#include "EmulateFixture.h"
21
 
22
TEST_F(EmulateFixture, XchgRegReg8)
23
{
24
    // xchg al, bl
25
    set_instruction({0x86, 0xc3});
26
    write_reg(AL, 0xaa);
27
    write_reg(BL, 0xbb);
28
 
29
    emulate();
30
 
31
    ASSERT_EQ(read_reg(AL), 0xbb);
32
    ASSERT_EQ(read_reg(BL), 0xaa);
33
}
34
 
35
TEST_F(EmulateFixture, XchgRegReg16)
36
{
37
    // xchg bx, cx
38
    set_instruction({0x87, 0xd9});
39
    write_reg(BX, 0xbbbb);
40
    write_reg(CX, 0xcccc);
41
 
42
    emulate();
43
 
44
    ASSERT_EQ(read_reg(BX), 0xcccc);
45
    ASSERT_EQ(read_reg(CX), 0xbbbb);
46
}
47
 
48
TEST_F(EmulateFixture, XchgRegMem8)
49
{
50
    // xchg al, [0x1234]
51
    set_instruction({0x86, 0x06, 0x34, 0x12});
52
    write_mem8(0x1234, 0x12);
53
    write_reg(AL, 0xaa);
54
 
55
    emulate();
56
 
57
    ASSERT_EQ(read_reg(AL), 0x12);
58
    ASSERT_EQ(read_mem8(0x1234), 0xaa);
59
}
60
 
61
TEST_F(EmulateFixture, XchgRegMem16)
62
{
63
    // xchg ax, [0x1234]
64
    set_instruction({0x87, 0x06, 0x34, 0x12});
65
    write_mem16(0x1234, 0x1234);
66
    write_reg(AX, 0xaaaa);
67
 
68
    emulate();
69
 
70
    ASSERT_EQ(read_reg(AX), 0x1234);
71
    ASSERT_EQ(read_mem16(0x1234), 0xaaaa);
72
}
73
 
74
TEST_F(EmulateFixture, XchgALALNop)
75
{
76
    // xchg al, al
77
    set_instruction({0x86, 0xc0});
78
    write_reg(AL, 0xaa);
79
 
80
    emulate();
81
 
82
    ASSERT_EQ(read_reg(AL), 0xaa);
83
}
84
 
85
class XchgAXFixture
86
    : public EmulateFixture,
87
      public ::testing::WithParamInterface<std::pair<uint8_t, GPR>>
88
{
89
};
90
TEST_P(XchgAXFixture, XchgRegAccumulator)
91
{
92
    // xchg ax, ?x
93
    set_instruction({GetParam().first});
94
    write_reg(AX, 0xaaaa);
95
    write_reg(GetParam().second, 0xbbbb);
96
 
97
    emulate();
98
 
99
    ASSERT_EQ(read_reg(AX), 0xbbbb);
100
    ASSERT_EQ(read_reg(GetParam().second), 0xaaaa);
101
}
102
INSTANTIATE_TEST_CASE_P(
103
    XchgAccumulator,
104
    XchgAXFixture,
105
    ::testing::Values(std::make_pair<uint8_t, GPR>(0x91, CX),
106
                      std::make_pair<uint8_t, GPR>(0x92, DX),
107
                      std::make_pair<uint8_t, GPR>(0x93, BX),
108
                      std::make_pair<uint8_t, GPR>(0x94, SP),
109
                      std::make_pair<uint8_t, GPR>(0x95, BP),
110
                      std::make_pair<uint8_t, GPR>(0x96, SI),
111
                      std::make_pair<uint8_t, GPR>(0x97, DI)));

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.