Added assembler check for string outside Data Segment.

This commit is contained in:
Anachronaut
2026-08-17 20:10:33 -04:00
parent 9e3425d34b
commit a842c884e8
7 changed files with 60 additions and 10 deletions
+9 -4
View File
@@ -42,7 +42,7 @@
//
// The top kilobyte of Program Memory is reserved for vectors. Both tools have to
// agree on where it begins: the CPU starts execution through it, and the assembler
// has to refuse program text that would run into it.
// has to refuse a Program Segment that would run into it.
//
// Entries are two bytes each, most significant byte first, the same order the branch
// instructions and this file format already use.
@@ -88,9 +88,14 @@
#define VECTOR_FIRST_PINNED 16
#define VECTOR_FIRST_AUTO 64
// The first address the vector table occupies, and so the first address that program
// text may not use.
#define PROGRAM_TEXT_LIMIT SOFTWARE_VECTOR_BASE
// The first address the vector table occupies, and so the first address the Program
// Segment may not reach.
//
// The Segment rather than the code: instructions are most of what goes there, but not all
// of it. Literal bytes go there, a label named in the Program Segment puts its two byte
// address there, and #Align and #Reserve put runs of zeroes there. What the limit measures
// is how far all of that together has pushed the cursor.
#define PROGRAM_SEGMENT_LIMIT SOFTWARE_VECTOR_BASE
#define SPLITBIT_MAGIC "SPBT"
#define SPLITBIT_MAGIC_LENGTH 4
+22 -2
View File
@@ -330,9 +330,29 @@ int loadFile(intermediateElement **intermediateArray, char *fileName, int *inter
printf(" File: %s at line %d.\n", fileName, lineNumber);
exit(1);
}
// A string, which only the Data Segment can hold. Nothing below this line looks at
// strings, so without this they would fall past every check and out the bottom,
// and a string written anywhere else would assemble to nothing at all and say so
// to nobody.
} else if ((*intermediateArray)[*intermediateIndex].type == STRING) {
if (status == PROGRAM) {
fprintf(stderr, RED "Error: A string cannot go in the Program Segment.\n"
" Strings live in Data Memory, which is the only memory an instruction\n"
" can read. A string in Program Memory could not be reached even by the\n"
" program holding it, except through the memory controller.\n" RESET);
printf(" File: %s at line %d.\n", fileName, lineNumber);
printf(" The string: \"%s\"\n", (*intermediateArray)[*intermediateIndex].token);
printf(" Move it below a #Data line.\n");
exit(1);
}
if (status != DATA) {
fprintf(stderr, RED "Error: Attempting to write a string to nowhere!\n Did you forget to use the #Data keyword?\n" RESET);
printf(" File: %s at line %d.\n", fileName, lineNumber);
printf(" The string: \"%s\"\n", (*intermediateArray)[*intermediateIndex].token);
exit(1);
}
// Finally, check if it's a label or label definition.
// First, make sure it hasn't already been marked as a string literal.
} else if ((*intermediateArray)[*intermediateIndex].type != STRING) {
} else {
if (checkIfLabel(&(*intermediateArray)[*intermediateIndex])) {
if (status == NOWHERE) {
fprintf(stderr, RED "Error: Attempting to create or use a label nowhere!\n Did you forget to use the #Program or #Data keyword?\n" RESET);
+3 -3
View File
@@ -96,10 +96,10 @@ void populateLabelTable(intermediateElement *intermediateArray, int arraySize) {
if (debugSecondPass) printf("Token: %s with byte length %d to destination %d of type %d\n", intermediateArray[i].token ,intermediateArray[i].byteLength, intermediateArray[i].destination, intermediateArray[i].type);
}
if (programCount > PROGRAM_TEXT_LIMIT ) {
if (programCount > PROGRAM_SEGMENT_LIMIT ) {
fprintf(stderr, RED "Error: Program is too long to fit in Program Memory.\n"
" Program text may not run past 0x%04X, where the vector table begins.\n" RESET,
PROGRAM_TEXT_LIMIT - 1);
" The Program Segment may not run past 0x%04X, where the vector table begins.\n" RESET,
PROGRAM_SEGMENT_LIMIT - 1);
exit(1);
}
if (dataCount > 0xFFFF ) {