diff --git a/src/asm/rpn.c b/src/asm/rpn.c index 24f43239..6ca9174c 100644 --- a/src/asm/rpn.c +++ b/src/asm/rpn.c @@ -106,7 +106,10 @@ void rpn_Symbol(struct Expression *expr, char *tzSym) { struct sSymbol *sym = sym_FindSymbol(tzSym); - if (!sym || !sym_IsConstant(sym)) { + if (sym == pPCSymbol && !pPCSymbol->pSection) { + yyerror("PC has no value outside a section"); + rpn_Number(expr, 0); + } else if (!sym || !sym_IsConstant(sym)) { rpn_Init(expr); expr->isSymbol = true; diff --git a/src/asm/symbol.c b/src/asm/symbol.c index 6b18ed3e..9d969539 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -230,7 +230,9 @@ uint32_t sym_GetConstantValue(char const *s) struct sSymbol const *psym = sym_FindSymbol(s); if (psym == pPCSymbol) { - if (pCurrentSection->nOrg == -1) + if (!pCurrentSection) + yyerror("PC has no value outside a section"); + else if (pCurrentSection->nOrg == -1) yyerror("Expected constant PC but section is not fixed"); else return sym_GetValue(psym); diff --git a/test/asm/assert@-no-sect.asm b/test/asm/assert@-no-sect.asm new file mode 100644 index 00000000..7df8df79 --- /dev/null +++ b/test/asm/assert@-no-sect.asm @@ -0,0 +1 @@ +assert @ || 1 diff --git a/test/asm/assert@-no-sect.err b/test/asm/assert@-no-sect.err new file mode 100644 index 00000000..68c7d037 --- /dev/null +++ b/test/asm/assert@-no-sect.err @@ -0,0 +1,3 @@ +ERROR: assert@-no-sect.asm(1): + PC has no value outside a section +error: Assembly aborted (1 errors)! diff --git a/test/asm/assert@-no-sect.out b/test/asm/assert@-no-sect.out new file mode 100644 index 00000000..e69de29b diff --git a/test/asm/if@-no-sect.asm b/test/asm/if@-no-sect.asm new file mode 100644 index 00000000..7c6072d9 --- /dev/null +++ b/test/asm/if@-no-sect.asm @@ -0,0 +1,2 @@ +if {@} +endc diff --git a/test/asm/if@-no-sect.err b/test/asm/if@-no-sect.err new file mode 100644 index 00000000..197db7bd --- /dev/null +++ b/test/asm/if@-no-sect.err @@ -0,0 +1,3 @@ +ERROR: if@-no-sect.asm(1): + PC has no value outside a section +error: Assembly aborted (1 errors)! diff --git a/test/asm/if@-no-sect.out b/test/asm/if@-no-sect.out new file mode 100644 index 00000000..e69de29b