I am debugging an issue I have on a legacy codebase that is running on an atxmega32c4u chip. I am writing single bytes to registers in PORTC, but the memory view is showing multiple bytes change. The videos below show this happening when stepping through with the debugger, both in the C-code as well as the disassembly.
The std
instruction is executing and writing to the expected base memory address, however the memory view shows multiple bytes changing after the instruction is executed, whereas the instruction set manual says that only a single byte will be mutated.
I expected that only addresses 0x640
(PORTC.DIR
) and 0x644
(PORTC.OUT
) would be written to, however the memory view is showing that addresses 0x640 - 0x648
are being written to with these two lines.
ANSWER
Thanks to user justme - the answer is in the register description (RTFM!). The addresses that are being "mutated" are not actually changing - they are the SET
, CLR
, and TGL
registers for DIR
and OUT
. For the DIRSET
, DIRCLR
, and DIRTGL
registers, the manual says:
Reading this register will return the value of the DIR register.
Original question
Setup
- MCU: atxmega32c4u
- Debugger: Atmel-ICE
- IDE: Microchip studio v 7.0.2542
Code
C-code
{
PORTC.OUT = 0xfe;
PORTC.DIR = 0x88;
while(1);
// rest of the codebase omitted
}
Disassembly
PORTC.OUT = 0xfe;
00001873 LDI R24,0x40 Load immediate
00001874 LDI R25,0x06 Load immediate
00001875 LDI R18,0xFE Load immediate
00001876 MOVW R30,R24 Copy register pair
00001877 STD Z+4,R18 Store indirect with displacement
PORTC.DIR = 0x88;
00001878 LDI R24,0x40 Load immediate
00001879 LDI R25,0x06 Load immediate
0000187A LDI R18,0x88 Load immediate
0000187B MOVW R30,R24 Copy register pair
0000187C STD Z+0,R18 Store indirect with displacement
while(1);
0000187D RJMP PC-0x0000 Relative jump
Videos
This screen capture shows me stepping through the C code and watching the bytes change in the memory view.
This screen capture shows me stepping through the disassembly and watching the bytes change in the memory view. The bytes change after the std
instruction, which, according to the user manual, should only write a single byte to the destination address.