2020-09-18 02:35 PM
I'm trying to write an emulator for the STM8 MCU family. Most of the opcodes are implemented, but it's doing things I don't expect, and I think the problem lies in some of my addressing mode implementations. The following questions seem obvious, but I'm just trying to confirm.
According to the STM8 programmer's manual PM0044, short indexed addressing modes with X/Y allow only a 00..1FE address range. So this means that only the low bytes of X/Y are used as the index, correct?
Also, the no offset indexed addressing modes are said to have an 00..FF address range. So same deal? Only use the low bytes of the index registers X/Y?
2020-09-19 04:42 AM
Hi!
"short indexed addressing modes with X/Y allow only a 00..1FE address range" - not so.
It is quite simple. Indexed means it uses a register (X, Y, SP) for the address computation. To the 16-bit content of the register you can add a constant offset for the final address. If this offset is 1 byte than it's short (so +0x00..0xFF), if it's 2 bytes is long and if it's 3 bytes is extended addressing mode.
If you don't add any offset to the registers used as index, than it's "indexed, no offset".
2020-09-19 11:21 AM
Right, I understand the basic idea, but was trying to figure out if an indexed instruction with a 1 byte offset only uses the lower byte of the index register, say XL. Rather than the full X. When calculating the effective address.
2020-09-19 12:48 PM
No, it always uses the full X register. Below some examples:
"ldw X, #0x4455" this loads the value 0x4455 into X register;
"ld A, (7,X)" - this loads the byte from the memory location (0x4455 + 7) into A - it's short indexed addressing;
"ld A, (137,X)" - this loads the byte from the memory location (0x4455 + 137) into A - it's also short indexed addressing;
"ld A, (777,X)" - this loads the byte from the memory location 0x4455 + 777 into A - it's long indexed addressing, and it will fetch the same byte like the following instructions:
"ldw X, #777
ld A, (0x4455, X)"
2020-09-19 04:25 PM
Thanks for the clarification! So that would indicate that the programmer's manual is wrong. It claims the address range for those instructions is only 00..1FE which would imply the addition of two 8-bit values.
2020-09-20 01:21 AM
I don't know where you read that, it's not wrong. See next capture from the programming manual PM0044.