diff --git a/src/cpu/thumb/exec.cc b/src/cpu/thumb/exec.cc index 4123316..f26186e 100644 --- a/src/cpu/thumb/exec.cc +++ b/src/cpu/thumb/exec.cc @@ -499,10 +499,10 @@ Instruction::exec(Cpu& cpu) { } } } else { - for (int8_t i = 7; i >= 0; i--) { + for (uint8_t i = 0; i < 8; i++) { if (get_bit(data.regs, i)) { - rb -= alignment; cpu.bus->write_word(rb, cpu.gpr[i], sequential); + rb += alignment; sequential = true; } } diff --git a/tests/cpu/thumb/exec.cc b/tests/cpu/thumb/exec.cc index b98d686..aa056a4 100644 --- a/tests/cpu/thumb/exec.cc +++ b/tests/cpu/thumb/exec.cc @@ -855,18 +855,19 @@ TEST_CASE_METHOD(CpuFixture, "Multiple Load/Store", TAG) { setr(6, 131313333); setr(7, 131); - // set R2 (base) to top of stack - setr(2, address + alignment * 5); + // base + setr(2, address); exec(data); CHECK(bus->read_word(address) == 237164); - CHECK(bus->read_word(address + alignment) == address + alignment * 5); + CHECK(bus->read_word(address + alignment) == address); CHECK(bus->read_word(address + alignment * 2) == 905895898); CHECK(bus->read_word(address + alignment * 3) == 131313333); CHECK(bus->read_word(address + alignment * 4) == 131); + // write back - CHECK(getr(2) == address); + CHECK(getr(2) == address + alignment * 5); } SECTION("load") {