Skip to content

Commit 158a2a7

Browse files
committed
No longer use register names in I/O space for ldi operands
When disassembling AVRDUDE uses known labels for ldi operations that initialise a register pair, eg, ldi r30, lo8(nvm.ctrla) ; 0xcb = 203 ldi r31, hi8(nvm.ctrla) ; 0x01 = 1 out cpu.ccp, r24 st Z, r18 This is meant to illustrate a possible intention of the code. It is not unusual to see a base register loaded, for example the USARTC0 register base, into the Y or Z register pair and read write with displacement from specific USARTC0 register bytes using the ldd and std opcodes. However, sometimes these labels are misleading when, eg, the register pair is just initialised as a counter. In particular that can easily happen for I/O register addresses for which there are fewer use cases to put them into a register pair as the in/out opcodes are short and no savings would be made using ldd/std. For example, ldi r28, lo8(gpio.gpior9) ; 0x09 = 9 ldi r29, hi8(gpio.gpior9) ; 0x00 = 0 is most likely used as a 16-bit counter initialised with 9. This would better be disassembled as ldi r28, 0x09 ; 9 ldi r29, 0x00 ; 0 This commit does so by removing the use of registers in I/O space as symbolic ldi operands when loading a register pair.
1 parent 6350272 commit 158a2a7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/disasm.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,11 @@ static const char *get_ldi_name(int op1, int op2, Op_context *oxp) {
922922
if((s = find_symbol(*c, addr*awidth)))
923923
break;
924924
if(s && s->name) { // Label matches the address loaded into register pair
925-
s->used = 1;
926-
return str_ccprintf("%s%s(%s)", awidth == 2? "pm_": "", ra & 1? "hi8": "lo8", s->name);
925+
// Don't use register names in I/O space as ldi label names
926+
if(s->type != 'M' || (uint16_t) addr >= 64 + cx->dis_io_offset) {
927+
s->used = 1;
928+
return str_ccprintf("%s%s(%s)", awidth == 2? "pm_": "", ra & 1? "hi8": "lo8", s->name);
929+
}
927930
}
928931
if((ra | 1) == 31 && oxp->is_lpm && addr >= cx->dis_start && addr < cx->dis_end) {
929932
if(cx->dis_pass == 1)

0 commit comments

Comments
 (0)