add push pop
This commit is contained in:
parent
7bf7eae401
commit
c32251b5a0
49
asm/main.c
49
asm/main.c
@ -488,6 +488,14 @@ void pline_free(PLine* pline)
|
|||||||
free(pline);
|
free(pline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PStmtTy_Line,
|
||||||
|
PStmtTy_Global,
|
||||||
|
PStmtTy_Extern,
|
||||||
|
PStmtTy_Include,
|
||||||
|
PStmtTy_Define,
|
||||||
|
} PStmtTy;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Lexer lexer;
|
Lexer lexer;
|
||||||
Tok tok;
|
Tok tok;
|
||||||
@ -1362,7 +1370,7 @@ typedef enum {
|
|||||||
M_iret, M_or, M_xor, M_and, M_shl, M_rshl,
|
M_iret, M_or, M_xor, M_and, M_shl, M_rshl,
|
||||||
M_shr, M_rshr, M_add, M_sub, M_rsub, M_mul,
|
M_shr, M_rshr, M_add, M_sub, M_rsub, M_mul,
|
||||||
M_imul, M_div, M_idiv, M_rdiv, M_ridiv, M_mod,
|
M_imul, M_div, M_idiv, M_rdiv, M_ridiv, M_mod,
|
||||||
M_rmod,
|
M_rmod, M_push, M_pop
|
||||||
// clang-format on
|
// clang-format on
|
||||||
} Mnemonic;
|
} Mnemonic;
|
||||||
|
|
||||||
@ -1374,7 +1382,7 @@ const char* mnemonic_str[] = {
|
|||||||
"iret", "or", "xor", "and", "shl", "rshl",
|
"iret", "or", "xor", "and", "shl", "rshl",
|
||||||
"shr", "rshr", "add", "sub", "rsub", "mul",
|
"shr", "rshr", "add", "sub", "rsub", "mul",
|
||||||
"imul", "div", "idiv", "rdiv", "ridiv", "mod",
|
"imul", "div", "idiv", "rdiv", "ridiv", "mod",
|
||||||
"rmod",
|
"rmod", "push", "pop"
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1985,7 +1993,44 @@ static inline uint16_t pline_assemble(OperandEvaluator* evaluator,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case M_push:
|
||||||
|
if (line->ops_size == 1) {
|
||||||
|
EvaledOperand op1 = eval_operand(evaluator, line->ops[0]);
|
||||||
|
CHECK_OPERAND(op1);
|
||||||
|
if (op1.ty == EoTy_Reg) {
|
||||||
|
uint16_t size = 0;
|
||||||
|
Line l;
|
||||||
|
l = s_add_i(Rsp, Rsp, 2);
|
||||||
|
size += assemble_line(object, &l);
|
||||||
|
l = s_mov16_mr_r(Rsp, 0, op1.reg);
|
||||||
|
size += assemble_line(object, &l);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
if (op1.ty == EoTy_Imm) {
|
||||||
|
uint16_t size = 0;
|
||||||
|
Line l;
|
||||||
|
l = s_add_i(Rsp, Rsp, 2);
|
||||||
|
size += assemble_line(object, &l);
|
||||||
|
l = s_mov16_mr_i(Rsp, 0, op1.imm);
|
||||||
|
size += assemble_line(object, &l);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
case M_pop:
|
||||||
|
if (line->ops_size == 1) {
|
||||||
|
EvaledOperand op1 = eval_operand(evaluator, line->ops[0]);
|
||||||
|
CHECK_OPERAND(op1);
|
||||||
|
if (op1.ty == EoTy_Reg) {
|
||||||
|
uint16_t size = 0;
|
||||||
|
Line l;
|
||||||
|
l = s_mov16_r_mr(op1.reg, Rsp, 0);
|
||||||
|
size += assemble_line(object, &l);
|
||||||
|
l = s_sub_i(Rsp, Rsp, 2);
|
||||||
|
size += assemble_line(object, &l);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
reporter_error_with_loc(rep, "malformed instruction", line->loc);
|
reporter_error_with_loc(rep, "malformed instruction", line->loc);
|
||||||
|
@ -25,22 +25,12 @@ interrupt_table:
|
|||||||
|
|
||||||
keyboard_interrupt:
|
keyboard_interrupt:
|
||||||
and rfl, rfl, !(1 << 5) ; Fl_Int
|
and rfl, rfl, !(1 << 5) ; Fl_Int
|
||||||
; push rbp
|
push rbp
|
||||||
add rsp, rsp, 2
|
|
||||||
mov u16 [rsp], rbp
|
|
||||||
mov rbp, rsp
|
mov rbp, rsp
|
||||||
; push r0
|
push r0
|
||||||
add rsp, rsp, 2
|
push r1
|
||||||
mov u16 [rsp], r0
|
push r2
|
||||||
; push r1
|
push r3
|
||||||
add rsp, rsp, 2
|
|
||||||
mov u16 [rsp], r1
|
|
||||||
; push r2
|
|
||||||
add rsp, rsp, 2
|
|
||||||
mov u16 [rsp], r2
|
|
||||||
; push r3
|
|
||||||
add rsp, rsp, 2
|
|
||||||
mov u16 [rsp], r3
|
|
||||||
|
|
||||||
in r0, 0 ; Device_Keyboard
|
in r0, 0 ; Device_Keyboard
|
||||||
|
|
||||||
@ -96,22 +86,12 @@ keyboard_interrupt:
|
|||||||
|
|
||||||
.L4:
|
.L4:
|
||||||
|
|
||||||
; pop r3
|
pop r3
|
||||||
mov r3, u16 [rsp]
|
pop r2
|
||||||
sub rsp, rsp, 2
|
pop r1
|
||||||
; pop r2
|
pop r0
|
||||||
mov r2, u16 [rsp]
|
|
||||||
sub rsp, rsp, 2
|
|
||||||
; pop r1
|
|
||||||
mov r1, u16 [rsp]
|
|
||||||
sub rsp, rsp, 2
|
|
||||||
; pop r0
|
|
||||||
mov r0, u16 [rsp]
|
|
||||||
sub rsp, rsp, 2
|
|
||||||
mov rsp, rbp
|
mov rsp, rbp
|
||||||
; pop rbp
|
pop rbp
|
||||||
mov rbp, u16 [rsp]
|
|
||||||
sub rsp, rsp, 2
|
|
||||||
or rfl, rfl, 1 << 5 ; Fl_Int
|
or rfl, rfl, 1 << 5 ; Fl_Int
|
||||||
iret
|
iret
|
||||||
|
|
||||||
@ -152,16 +132,10 @@ put_char:
|
|||||||
mov u16 [screen_x], r1
|
mov u16 [screen_x], r1
|
||||||
|
|
||||||
.L1:
|
.L1:
|
||||||
; pop r1
|
pop r1
|
||||||
mov r1, u16 [rsp]
|
pop r2
|
||||||
sub rsp, rsp, 2
|
|
||||||
; pop r2
|
|
||||||
mov r2, u16 [rsp]
|
|
||||||
sub rsp, rsp, 2
|
|
||||||
mov rsp, rbp
|
mov rsp, rbp
|
||||||
; pop rbp
|
pop rbp
|
||||||
mov rbp, u16 [rsp]
|
|
||||||
sub rsp, rsp, 2
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
screen_x:
|
screen_x:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user