jsmolka / gba-tests

A collection of Game Boy Advance tests.
MIT License
101 stars 9 forks source link

arm block transfer ldmia empty rlist #12

Closed DipeshChouhan closed 1 year ago

DipeshChouhan commented 1 year ago

Is it always going to fail. Because pc is never updated for next instruction. ldmia r0!, {}

jsmolka commented 1 year ago

No, it reads the word at address r0 into the pc, just as described in the test.

t513:
        ; ARM 10: Load empty rlist
        adr     r0, t514
        str     r0, [mem]
        mov     r0, mem
        dw      0xE8B00000  ; ldmia r0!, {}

f513:
        m_exit  513

t514:
DipeshChouhan commented 1 year ago

Is it adr instruction. My decoder decoding it as add instruction

jsmolka commented 1 year ago

The adr instruction loads the address of label t514 into r0. This is done by the assembler and ends up being an add instruction.

DipeshChouhan commented 1 year ago

Sorry for asking another question but which instruction is going to load pc. My emulator just exit with 513 code. Is pc (r15) included in ldmia r0!, {}

fleroviux commented 1 year ago

ldm with an empty register list loads from the base register into r15 and updates the base register by +/- 64 (if writeback is enabled). This is likely due to quirks in how the hardware finds the next set bit in the register list (trailing zero count) as well as how it computes the sum of set bits (population count) when the register list is empty.

DipeshChouhan commented 1 year ago

Is it undefined behavior

jsmolka commented 1 year ago

Yes, it is. You don't need it for an emulator, but I included it out of curiosity.

DipeshChouhan commented 1 year ago

Thanks for your help.