diff --git a/src/asm/section.cpp b/src/asm/section.cpp index 7faa60be..b9e34233 100644 --- a/src/asm/section.cpp +++ b/src/asm/section.cpp @@ -572,18 +572,28 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset) { uint32_t alignSize = 1 << alignment; // Size of an aligned "block" if (sect->org != UINT32_MAX) { - if ((sect->org + curOffset - offset) % alignSize) { + if (uint32_t actualOffset = (sect->org + curOffset) % alignSize; actualOffset != offset) { error( - "Section's fixed address fails required alignment (PC = $%04" PRIx32 ")\n", - sect->org + curOffset + "Section is misaligned (at PC = $%04" PRIx32 ", expected ALIGN[%" PRIu32 + ", %" PRIu32 "], got ALIGN[%" PRIu32 ", %" PRIu32 "])\n", + sect->org + curOffset, + alignment, + offset, + alignment, + actualOffset ); } - } else if (sect->align != 0 - && (((sect->alignOfs + curOffset) % (1u << sect->align)) - offset) % alignSize) { + } else if (uint32_t actualOffset = + ((sect->alignOfs + curOffset) % (1u << sect->align)) % alignSize; + sect->align != 0 && actualOffset != offset) { error( - "Section's alignment fails required alignment (offset from section start = $%04" PRIx32 - ")\n", - curOffset + "Section is misaligned ($%04" PRIx32 " bytes into the section, expected ALIGN[%" PRIu32 + ", %" PRIu32 "], got ALIGN[%" PRIu32 ", %" PRIu32 "])\n", + curOffset, + alignment, + offset, + alignment, + actualOffset ); } else if (alignment >= 16) { // Treat an alignment large enough as fixing the address. diff --git a/test/asm/fragment-align.err b/test/asm/fragment-align.err index 7377752c..d28f2da2 100644 --- a/test/asm/fragment-align.err +++ b/test/asm/fragment-align.err @@ -1,3 +1,3 @@ error: fragment-align.asm(25): - Section's alignment fails required alignment (offset from section start = $0004) + Section is misaligned ($0004 bytes into the section, expected ALIGN[2, 0], got ALIGN[2, 1]) error: Assembly aborted (1 error)! diff --git a/test/asm/invalid-alignment.err b/test/asm/invalid-alignment.err index 17a8ff20..b7892b4f 100644 --- a/test/asm/invalid-alignment.err +++ b/test/asm/invalid-alignment.err @@ -1,5 +1,5 @@ error: invalid-alignment.asm(9): - Section's fixed address fails required alignment (PC = $4000) + Section is misaligned (at PC = $4000, expected ALIGN[16, 0], got ALIGN[16, 16384]) error: invalid-alignment.asm(11): Alignment must be between 0 and 16, not 20 error: invalid-alignment.asm(13):