ps5: task 2

This commit is contained in:
2026-03-28 21:22:11 +01:00
parent 8363e4bab8
commit 2bbc045294

View File

@@ -76,6 +76,25 @@ static void generate_global_variables(void)
// As an example, to set aside 16 bytes and label it .myBytes, write:
// DIRECTIVE(".myBytes: .zero 16")
for (int i = 0; i < global_symbols->n_children; i++) {
symbol_t *sym = global_symbols->children[i];
switch (sym->type) {
case SYMBOL_GLOBAL_VAR:
DIRECTIVE(".%s:\t.zero 8", sym.name);
break;
case SYMBOL_GLOBAL_ARRAY:
node_t num = sym->node->children[1];
assert(num->type == NUMBER_LITERAL);
int len = num->data.number_literal * 8;
DIRECTIVE(".%s:\t.zero %d", sym.name, len);
break;
case SYMBOL_FUNCTION:
break;
default:
fprintf(stderr, "unexpected global symbol");
exit(EXIT_FAILURE);
}
}
}
// Global variable used to make the functon currently being generated accessible from anywhere