diff --git a/MC6809/src/mc6809.cpp b/MC6809/src/mc6809.cpp index afd6c2c..421c01c 100644 --- a/MC6809/src/mc6809.cpp +++ b/MC6809/src/mc6809.cpp @@ -783,8 +783,10 @@ uint8_t EightBit::mc6809::asl(uint8_t operand) { } uint8_t EightBit::mc6809::asr(uint8_t operand) { - setFlag(CC(), CF, operand & Bit7); - adjustNZ(operand >>= 1); + setFlag(CC(), CF, operand & Bit0); + operand >>= 1; + operand |= Bit7; + adjustNZ(operand); return operand; } diff --git a/MC6809/unittest/mc6809_tests.cpp b/MC6809/unittest/mc6809_tests.cpp index 7a4c621..1567507 100644 --- a/MC6809/unittest/mc6809_tests.cpp +++ b/MC6809/unittest/mc6809_tests.cpp @@ -104,3 +104,22 @@ TEST_CASE("Shift Accumulator or Memory Byte Left", "[ASL][ASLA]") { REQUIRE(cpu.cycles() == 2); } } + +TEST_CASE("Shift Accumulator or Memory Byte Right", "[ASR][ASRA]") { + + Board board; + board.initialise(); + auto& cpu = board.CPU(); + cpu.step(); // Step over the reset + + SECTION("Inherent") { + board.poke(0, 0x47); + cpu.A() = 0xcb; + cpu.step(); + REQUIRE(cpu.A() == 0xe5); + REQUIRE((cpu.CC() & EightBit::mc6809::CF) != 0); + REQUIRE((cpu.CC() & EightBit::mc6809::ZF) == 0); + REQUIRE((cpu.CC() & EightBit::mc6809::NF) != 0); + REQUIRE(cpu.cycles() == 2); + } +}