From f5aa73e7cae0c5f8e6f5a099587736c80624120b Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Wed, 19 Jun 2024 14:18:37 +0530 Subject: [PATCH] cpu/thumb: fix multiple load/store Signed-off-by: Amneesh Singh --- src/cpu/thumb/exec.cc | 4 ++-- tests/cpu/thumb/exec.cc | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) 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") {