don't use rsp in indirection

This commit is contained in:
sfja 2025-04-02 16:32:51 +02:00
parent c32251b5a0
commit bdff748461
2 changed files with 33 additions and 16 deletions

@ -492,10 +492,32 @@ typedef enum {
PStmtTy_Line,
PStmtTy_Global,
PStmtTy_Extern,
PStmtTy_Include,
PStmtTy_Define,
} PStmtTy;
typedef struct {
PStmtTy ty;
union {
PLine* line;
char* ident;
};
} PStmt;
void pstmt_free(PStmt* stmt)
{
switch (stmt->ty) {
case PStmtTy_Line:
pline_free(stmt->line);
break;
case PStmtTy_Global:
case PStmtTy_Extern:
case PStmtTy_Define:
free(stmt->ident);
break;
}
free(stmt);
}
typedef struct {
Lexer lexer;
Tok tok;
@ -1063,7 +1085,7 @@ typedef struct {
typedef struct {
IdentResolver* re;
Reporter* rep;
bool unresolve_is_error;
bool second_pass;
} OperandEvaluator;
static inline uint16_t eval_poperandty_unary(POperandTy ty, uint16_t operand)
@ -1131,7 +1153,7 @@ EvaledOperand eval_operand_to_imm(
const IdentResol* re
= ident_resolver_resolve(evaluator->re, operand->str);
if (re == NULL) {
if (!evaluator->unresolve_is_error) {
if (!evaluator->second_pass) {
return (EvaledOperand) { .ty = EoTy_Imm, .imm = 0 };
}
REPORTF_ERROR("undefined identifier '%s'", operand->str);
@ -2109,7 +2131,7 @@ int main(int argc, char** argv)
OperandEvaluator evaluator = {
.re = &resolver,
.rep = &rep,
.unresolve_is_error = false,
.second_pass = false,
};
size_t chunk_capacity = 64;
@ -2120,9 +2142,10 @@ int main(int argc, char** argv)
int res = define_labels(&resolver, lines[i]->labels, ip, &rep);
if (res != 0)
errors_occured = true;
ip += pline_assemble(&evaluator, chunk, lines[i], &rep);
if (ip == 0)
uint16_t size = pline_assemble(&evaluator, chunk, lines[i], &rep);
if (size == 0)
errors_occured = true;
ip += size;
}
if (errors_occured) {
@ -2131,7 +2154,7 @@ int main(int argc, char** argv)
goto leave_free_chunk;
}
evaluator.unresolve_is_error = true;
evaluator.second_pass = true;
FILE* output_fp = fopen(args.output_file, "wb");
if (!output_fp) {

@ -96,16 +96,10 @@ keyboard_interrupt:
iret
put_char:
; push rbp
add rsp, rsp, 2
mov u16 [rsp], rbp
push rbp
mov rbp, rsp
; push r1
add rsp, rsp, 2
mov u16 [rsp], r1
; push r2
add rsp, rsp, 2
mov u16 [rsp], r2
push r1
push r2
mov r2, u16 [screen_y]
mul r2, r2, 40 ; vcd_width_in_ch