Compare commits
No commits in common. "0bdbaa7f1fb731fcb3a48473d07e9cbc4c0f59c0" and "4f6520c47015f14463631fe08b91bb704b2f04ab" have entirely different histories.
0bdbaa7f1f
...
4f6520c470
1
Makefile
1
Makefile
@ -8,6 +8,7 @@ C_FLAGS = \
|
|||||||
-Wall -Wextra -Wpedantic -Wconversion \
|
-Wall -Wextra -Wpedantic -Wconversion \
|
||||||
-pedantic -pedantic-errors \
|
-pedantic -pedantic-errors \
|
||||||
-Wno-unused-variable \
|
-Wno-unused-variable \
|
||||||
|
-Wno-unused-parameter \
|
||||||
-I. \
|
-I. \
|
||||||
|
|
||||||
L_FLAGS = -pthread
|
L_FLAGS = -pthread
|
||||||
|
@ -114,7 +114,7 @@ typedef struct {
|
|||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
} Line;
|
} Line;
|
||||||
|
|
||||||
uint16_t assemble_lines_with_labels(
|
uint16_t assemble_to_binary(
|
||||||
uint16_t* out, const Line* lines, size_t lines_size);
|
uint16_t* out, const Line* lines, size_t lines_size);
|
||||||
|
|
||||||
Line s_label(int label);
|
Line s_label(int label);
|
||||||
|
@ -105,7 +105,6 @@ Line s_jnz_l(Reg op1_reg, int op2_label)
|
|||||||
{
|
{
|
||||||
return (Line) {
|
return (Line) {
|
||||||
.ty = LineTy_Jnz_Label,
|
.ty = LineTy_Jnz_Label,
|
||||||
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
|
|
||||||
.op2 = (Ex) { .label = op2_label },
|
.op2 = (Ex) { .label = op2_label },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
175
asm/main.c
175
asm/main.c
@ -37,8 +37,6 @@ typedef enum {
|
|||||||
TT_Int,
|
TT_Int,
|
||||||
TT_Binary,
|
TT_Binary,
|
||||||
TT_Hex,
|
TT_Hex,
|
||||||
TT_Char,
|
|
||||||
TT_Str,
|
|
||||||
TT_Newline = '\n',
|
TT_Newline = '\n',
|
||||||
TT_DoubleLt,
|
TT_DoubleLt,
|
||||||
TT_DoubleGt,
|
TT_DoubleGt,
|
||||||
@ -121,18 +119,6 @@ static inline Tok lexer_tok(const Lexer* lexer, TokTy ty, Loc loc)
|
|||||||
return (Tok) { .ty = ty, .loc = loc, .len = lexer->idx - loc.idx };
|
return (Tok) { .ty = ty, .loc = loc, .len = lexer->idx - loc.idx };
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int lexer_skip_literal_char(Lexer* lexer)
|
|
||||||
{
|
|
||||||
char ch = lexer->ch;
|
|
||||||
lexer_step(lexer);
|
|
||||||
if (ch == '\\') {
|
|
||||||
if (lexer_done(lexer))
|
|
||||||
return -1;
|
|
||||||
lexer_step(lexer);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void lexer_report(Lexer* lexer, const char* msg, Loc loc)
|
static inline void lexer_report(Lexer* lexer, const char* msg, Loc loc)
|
||||||
{
|
{
|
||||||
lexer->error_occured = true;
|
lexer->error_occured = true;
|
||||||
@ -152,7 +138,7 @@ static inline void lexer_report(Lexer* lexer, const char* msg, Loc loc)
|
|||||||
int line_len = (int)line_end - (int)line_start;
|
int line_len = (int)line_end - (int)line_start;
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"error: %s\n --> %s:%d:%d\n |\n%5d|%.*s\n |%*c^\n",
|
"error: %s\n --> %s:%d:%d\n |\n%5d|%.*s\n |%*c^\n",
|
||||||
msg,
|
msg,
|
||||||
lexer->filename,
|
lexer->filename,
|
||||||
loc.line,
|
loc.line,
|
||||||
@ -160,14 +146,14 @@ static inline void lexer_report(Lexer* lexer, const char* msg, Loc loc)
|
|||||||
loc.line,
|
loc.line,
|
||||||
line_len,
|
line_len,
|
||||||
line,
|
line,
|
||||||
loc.col - 1,
|
loc.col - 2,
|
||||||
' ');
|
' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
Tok lexer_next(Lexer* lexer)
|
Tok lexer_next(Lexer* lexer)
|
||||||
{
|
{
|
||||||
const char* ident_chars = "abcdefghijklmnopqrstuvwxyz"
|
const char* ident_chars = "abcdefghijklmnopqrstuvwxyz"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ_$";
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
|
||||||
const char* int_chars = "1234567890";
|
const char* int_chars = "1234567890";
|
||||||
const char* hex_chars = "01234567889abcdefABCDEF";
|
const char* hex_chars = "01234567889abcdefABCDEF";
|
||||||
|
|
||||||
@ -226,26 +212,6 @@ Tok lexer_next(Lexer* lexer)
|
|||||||
} else {
|
} else {
|
||||||
return lexer_tok(lexer, TT_Int, loc);
|
return lexer_tok(lexer, TT_Int, loc);
|
||||||
}
|
}
|
||||||
} else if (lexer->ch == '\'') {
|
|
||||||
lexer_step(lexer);
|
|
||||||
lexer_skip_literal_char(lexer);
|
|
||||||
if (lexer_done(lexer) || lexer->ch != '\'') {
|
|
||||||
lexer_report(lexer, "malformed character literal", loc);
|
|
||||||
return lexer_tok(lexer, TT_Err, loc);
|
|
||||||
}
|
|
||||||
lexer_step(lexer);
|
|
||||||
return lexer_tok(lexer, TT_Char, loc);
|
|
||||||
} else if (lexer->ch == '"') {
|
|
||||||
lexer_step(lexer);
|
|
||||||
while (!lexer_done(lexer) && lexer->ch != '"') {
|
|
||||||
lexer_skip_literal_char(lexer);
|
|
||||||
}
|
|
||||||
if (lexer_done(lexer) || lexer->ch != '"') {
|
|
||||||
lexer_report(lexer, "malformed string literal", loc);
|
|
||||||
return lexer_tok(lexer, TT_Err, loc);
|
|
||||||
}
|
|
||||||
lexer_step(lexer);
|
|
||||||
return lexer_tok(lexer, TT_Str, loc);
|
|
||||||
} else if (lexer->ch == '<') {
|
} else if (lexer->ch == '<') {
|
||||||
lexer_step(lexer);
|
lexer_step(lexer);
|
||||||
if (!lexer_done(lexer) && lexer->ch == '<') {
|
if (!lexer_done(lexer) && lexer->ch == '<') {
|
||||||
@ -269,9 +235,9 @@ Tok lexer_next(Lexer* lexer)
|
|||||||
lexer_step(lexer);
|
lexer_step(lexer);
|
||||||
return lexer_tok(lexer, (TokTy)ch, loc);
|
return lexer_tok(lexer, (TokTy)ch, loc);
|
||||||
} else {
|
} else {
|
||||||
lexer_report(lexer, "illegal character", loc);
|
lexer_report(lexer, "illegal character '%c'", loc);
|
||||||
lexer_step(lexer);
|
lexer_step(lexer);
|
||||||
return lexer_tok(lexer, TT_Err, loc);
|
return lexer_next(lexer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,7 +293,6 @@ typedef enum {
|
|||||||
PoTy_Imm,
|
PoTy_Imm,
|
||||||
PoTy_Ident,
|
PoTy_Ident,
|
||||||
PoTy_SubLabel,
|
PoTy_SubLabel,
|
||||||
PoTy_Str,
|
|
||||||
PoTy_MemU8,
|
PoTy_MemU8,
|
||||||
PoTy_MemU16,
|
PoTy_MemU16,
|
||||||
PoTy_Not,
|
PoTy_Not,
|
||||||
@ -352,7 +317,7 @@ struct POperand {
|
|||||||
union {
|
union {
|
||||||
Reg reg;
|
Reg reg;
|
||||||
uint16_t imm;
|
uint16_t imm;
|
||||||
char* str;
|
char* ident;
|
||||||
POperand* operand;
|
POperand* operand;
|
||||||
struct {
|
struct {
|
||||||
POperand* left;
|
POperand* left;
|
||||||
@ -373,10 +338,10 @@ POperand* poperand_new_imm(uint16_t imm, Loc loc)
|
|||||||
*operand = (POperand) { .ty = PoTy_Imm, .loc = loc, .imm = imm };
|
*operand = (POperand) { .ty = PoTy_Imm, .loc = loc, .imm = imm };
|
||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
POperand* poperand_new_str(POperandTy ty, char* str, Loc loc)
|
POperand* poperand_new_ident(POperandTy ty, char* ident, Loc loc)
|
||||||
{
|
{
|
||||||
POperand* operand = malloc(sizeof(POperand));
|
POperand* operand = malloc(sizeof(POperand));
|
||||||
*operand = (POperand) { .ty = ty, .loc = loc, .str = str };
|
*operand = (POperand) { .ty = ty, .loc = loc, .ident = ident };
|
||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
POperand* poperand_new_unary(POperandTy ty, POperand* inner, Loc loc)
|
POperand* poperand_new_unary(POperandTy ty, POperand* inner, Loc loc)
|
||||||
@ -401,8 +366,7 @@ void poperand_free(POperand* operand)
|
|||||||
break;
|
break;
|
||||||
case PoTy_Ident:
|
case PoTy_Ident:
|
||||||
case PoTy_SubLabel:
|
case PoTy_SubLabel:
|
||||||
case PoTy_Str:
|
free(operand->ident);
|
||||||
free(operand->str);
|
|
||||||
break;
|
break;
|
||||||
case PoTy_MemU8:
|
case PoTy_MemU8:
|
||||||
case PoTy_MemU16:
|
case PoTy_MemU16:
|
||||||
@ -435,19 +399,40 @@ typedef struct {
|
|||||||
POperand* ops[];
|
POperand* ops[];
|
||||||
} PLine;
|
} PLine;
|
||||||
|
|
||||||
PLine* pline_new(
|
PLine* pline_new_0(char* op, PLabel* labels, Loc loc)
|
||||||
char* op, PLabel* labels, Loc loc, size_t ops_size, POperand** ops)
|
|
||||||
{
|
{
|
||||||
PLine* line = malloc(sizeof(PLine) + sizeof(POperand*) * ops_size);
|
PLine* line = malloc(sizeof(PLine) + sizeof(POperand*) * 0);
|
||||||
*line = (PLine) {
|
*line = (PLine) { .labels = labels, .op = op, .loc = loc, .ops_size = 0 };
|
||||||
.labels = labels,
|
return line;
|
||||||
.op = op,
|
}
|
||||||
.loc = loc,
|
PLine* pline_new_1(char* op, PLabel* labels, Loc loc, POperand* op0)
|
||||||
.ops_size = ops_size,
|
{
|
||||||
};
|
PLine* line = malloc(sizeof(PLine) + sizeof(POperand*) * 1);
|
||||||
for (size_t i = 0; i < ops_size; ++i) {
|
*line = (PLine) { .labels = labels, .op = op, .loc = loc, .ops_size = 1 };
|
||||||
line->ops[i] = ops[i];
|
line->ops[0] = op0;
|
||||||
}
|
return line;
|
||||||
|
}
|
||||||
|
PLine* pline_new_2(
|
||||||
|
char* op, PLabel* labels, Loc loc, POperand* op0, POperand* op1)
|
||||||
|
{
|
||||||
|
PLine* line = malloc(sizeof(PLine) + sizeof(POperand*) * 2);
|
||||||
|
*line = (PLine) { .labels = labels, .op = op, .loc = loc, .ops_size = 2 };
|
||||||
|
line->ops[0] = op0;
|
||||||
|
line->ops[1] = op1;
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
PLine* pline_new_3(char* op,
|
||||||
|
PLabel* labels,
|
||||||
|
Loc loc,
|
||||||
|
POperand* op0,
|
||||||
|
POperand* op1,
|
||||||
|
POperand* op2)
|
||||||
|
{
|
||||||
|
PLine* line = malloc(sizeof(PLine) + sizeof(POperand*) * 3);
|
||||||
|
*line = (PLine) { .labels = labels, .op = op, .loc = loc, .ops_size = 3 };
|
||||||
|
line->ops[0] = op0;
|
||||||
|
line->ops[1] = op1;
|
||||||
|
line->ops[2] = op2;
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
void pline_free(PLine* pline)
|
void pline_free(PLine* pline)
|
||||||
@ -530,7 +515,7 @@ static inline void parser_report(Parser* parser, const char* msg, Loc loc)
|
|||||||
int line_len = (int)line_end - (int)line_start;
|
int line_len = (int)line_end - (int)line_start;
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"error: %s\n --> %s:%d:%d\n |\n%5d|%.*s\n |%*c^\n",
|
"error: %s\n --> %s:%d:%d\n |\n%5d|%.*s\n |%*c^\n",
|
||||||
msg,
|
msg,
|
||||||
parser->lexer.filename,
|
parser->lexer.filename,
|
||||||
loc.line,
|
loc.line,
|
||||||
@ -538,7 +523,7 @@ static inline void parser_report(Parser* parser, const char* msg, Loc loc)
|
|||||||
loc.line,
|
loc.line,
|
||||||
line_len,
|
line_len,
|
||||||
line,
|
line,
|
||||||
loc.col - 1,
|
loc.col - 2,
|
||||||
' ');
|
' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -587,24 +572,6 @@ static inline PLabel* parser_parse_labels(
|
|||||||
return labels;
|
return labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char literal_char_val(const char* str)
|
|
||||||
{
|
|
||||||
if (str[0] == '\\') {
|
|
||||||
switch (str[1]) {
|
|
||||||
case '0':
|
|
||||||
return 0;
|
|
||||||
case 't':
|
|
||||||
return '\t';
|
|
||||||
case 'n':
|
|
||||||
return '\n';
|
|
||||||
default:
|
|
||||||
return str[1];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return str[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int parser_binary_prec = 6;
|
static const int parser_binary_prec = 6;
|
||||||
static inline POperand* parser_parse_operand_2(Parser* parser, int prec);
|
static inline POperand* parser_parse_operand_2(Parser* parser, int prec);
|
||||||
|
|
||||||
@ -623,7 +590,7 @@ static inline POperand* parser_parse_operand_0(Parser* parser)
|
|||||||
return poperand_new_reg(reg_val[i], loc);
|
return poperand_new_reg(reg_val[i], loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return poperand_new_str(PoTy_Ident, ident, loc);
|
return poperand_new_ident(PoTy_Ident, ident, loc);
|
||||||
} else if (parser_eat(parser, TT_Int)) {
|
} else if (parser_eat(parser, TT_Int)) {
|
||||||
char* str = parser_ident_val(parser, parser->eaten);
|
char* str = parser_ident_val(parser, parser->eaten);
|
||||||
uint16_t imm = (uint16_t)strtoul(str, NULL, 10);
|
uint16_t imm = (uint16_t)strtoul(str, NULL, 10);
|
||||||
@ -639,28 +606,13 @@ static inline POperand* parser_parse_operand_0(Parser* parser)
|
|||||||
uint16_t imm = (uint16_t)strtoul(&str[2], NULL, 16);
|
uint16_t imm = (uint16_t)strtoul(&str[2], NULL, 16);
|
||||||
free(str);
|
free(str);
|
||||||
return poperand_new_imm(imm, loc);
|
return poperand_new_imm(imm, loc);
|
||||||
} else if (parser_eat(parser, TT_Char)) {
|
|
||||||
char* str = parser_ident_val(parser, parser->eaten);
|
|
||||||
uint16_t imm = (uint16_t)literal_char_val(&str[1]);
|
|
||||||
free(str);
|
|
||||||
return poperand_new_imm(imm, loc);
|
|
||||||
} else if (parser_eat(parser, TT_Str)) {
|
|
||||||
char* lit = parser_ident_val(parser, parser->eaten);
|
|
||||||
size_t lit_len = strlen(lit);
|
|
||||||
char* str = calloc(lit_len - 1, sizeof(char));
|
|
||||||
size_t str_len = 0;
|
|
||||||
for (size_t i = 1; i < lit_len - 2; ++i) {
|
|
||||||
str[i] = literal_char_val(&lit[i]);
|
|
||||||
}
|
|
||||||
free(lit);
|
|
||||||
return poperand_new_str(PoTy_Str, str, loc);
|
|
||||||
} else if (parser_eat(parser, '.')) {
|
} else if (parser_eat(parser, '.')) {
|
||||||
if (!parser_eat(parser, TT_Ident)) {
|
if (!parser_eat(parser, TT_Ident)) {
|
||||||
parser_report(parser, "expected identifier", parser->tok.loc);
|
parser_report(parser, "expected identifier", parser->tok.loc);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
char* ident = parser_ident_val(parser, parser->eaten);
|
char* ident = parser_ident_val(parser, parser->eaten);
|
||||||
return poperand_new_str(PoTy_SubLabel, ident, loc);
|
return poperand_new_ident(PoTy_SubLabel, ident, loc);
|
||||||
} else if (parser_eat(parser, '(')) {
|
} else if (parser_eat(parser, '(')) {
|
||||||
POperand* operand = parser_parse_operand_2(parser, parser_binary_prec);
|
POperand* operand = parser_parse_operand_2(parser, parser_binary_prec);
|
||||||
if (!parser_eat(parser, ')')) {
|
if (!parser_eat(parser, ')')) {
|
||||||
@ -745,18 +697,13 @@ static inline POperand* parser_parse_operand_2(Parser* parser, int prec)
|
|||||||
|
|
||||||
static inline POperand* parser_parse_operand_3(Parser* parser)
|
static inline POperand* parser_parse_operand_3(Parser* parser)
|
||||||
{
|
{
|
||||||
Loc loc = parser->tok.loc;
|
|
||||||
if (parser_eat(parser, TT_LBracket)) {
|
|
||||||
parser_report(parser, "expected 'u8' or 'u16'", loc);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!parser_test(parser, TT_Ident)) {
|
if (!parser_test(parser, TT_Ident)) {
|
||||||
return parser_parse_operand_2(parser, parser_binary_prec);
|
return parser_parse_operand_2(parser, parser_binary_prec);
|
||||||
}
|
}
|
||||||
char* ident = parser_ident_val(parser, parser->tok);
|
Loc loc = parser->tok.loc;
|
||||||
|
char* ident = parser_ident_val(parser, parser->eaten);
|
||||||
if (strcmp(ident, "u8") == 0) {
|
if (strcmp(ident, "u8") == 0) {
|
||||||
free(ident);
|
free(ident);
|
||||||
parser_step(parser);
|
|
||||||
if (!parser_eat(parser, '[')) {
|
if (!parser_eat(parser, '[')) {
|
||||||
parser_report(parser, "expected '['", parser->tok.loc);
|
parser_report(parser, "expected '['", parser->tok.loc);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -770,7 +717,6 @@ static inline POperand* parser_parse_operand_3(Parser* parser)
|
|||||||
return poperand_new_unary(PoTy_MemU8, operand, loc);
|
return poperand_new_unary(PoTy_MemU8, operand, loc);
|
||||||
} else if (strcmp(ident, "u16") == 0) {
|
} else if (strcmp(ident, "u16") == 0) {
|
||||||
free(ident);
|
free(ident);
|
||||||
parser_step(parser);
|
|
||||||
if (!parser_eat(parser, '[')) {
|
if (!parser_eat(parser, '[')) {
|
||||||
parser_report(parser, "expected '['", parser->tok.loc);
|
parser_report(parser, "expected '['", parser->tok.loc);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -794,9 +740,7 @@ PLine* parser_next(Parser* parser)
|
|||||||
Loc loc;
|
Loc loc;
|
||||||
PLabel* labels = parser_parse_labels(parser, &ident, &loc);
|
PLabel* labels = parser_parse_labels(parser, &ident, &loc);
|
||||||
|
|
||||||
const size_t max_ops_size = 64;
|
POperand* ops[3];
|
||||||
// TODO: Move allocation out-of-band.
|
|
||||||
POperand** ops = malloc(sizeof(POperand) * max_ops_size);
|
|
||||||
size_t ops_size = 0;
|
size_t ops_size = 0;
|
||||||
|
|
||||||
if (!parser_test(parser, TT_Eof) && !parser_test(parser, '\n')) {
|
if (!parser_test(parser, TT_Eof) && !parser_test(parser, '\n')) {
|
||||||
@ -807,12 +751,6 @@ PLine* parser_next(Parser* parser)
|
|||||||
ops[ops_size++] = operand;
|
ops[ops_size++] = operand;
|
||||||
while (!parser_test(parser, TT_Eof) && !parser_test(parser, '\n')
|
while (!parser_test(parser, TT_Eof) && !parser_test(parser, '\n')
|
||||||
&& ops_size < 3) {
|
&& ops_size < 3) {
|
||||||
if (ops_size >= max_ops_size) {
|
|
||||||
parser_report(parser,
|
|
||||||
"exceeded maximum number of operands (64)",
|
|
||||||
parser->tok.loc);
|
|
||||||
goto error_free_ops;
|
|
||||||
}
|
|
||||||
if (!parser_eat(parser, ',')) {
|
if (!parser_eat(parser, ',')) {
|
||||||
parser_report(parser, "expected ','", parser->tok.loc);
|
parser_report(parser, "expected ','", parser->tok.loc);
|
||||||
goto error_free_ops;
|
goto error_free_ops;
|
||||||
@ -830,15 +768,22 @@ PLine* parser_next(Parser* parser)
|
|||||||
}
|
}
|
||||||
parser_skip_newlines(parser);
|
parser_skip_newlines(parser);
|
||||||
|
|
||||||
PLine* line = pline_new(ident, labels, loc, ops_size, ops);
|
switch (ops_size) {
|
||||||
free(ops);
|
case 0:
|
||||||
return line;
|
return pline_new_0(ident, labels, loc);
|
||||||
|
case 1:
|
||||||
|
return pline_new_1(ident, labels, loc, ops[0]);
|
||||||
|
case 2:
|
||||||
|
return pline_new_2(ident, labels, loc, ops[0], ops[1]);
|
||||||
|
case 3:
|
||||||
|
default:
|
||||||
|
return pline_new_3(ident, labels, loc, ops[0], ops[1], ops[2]);
|
||||||
|
}
|
||||||
|
|
||||||
error_free_ops:
|
error_free_ops:
|
||||||
for (size_t i = 0; i < ops_size; ++i)
|
for (size_t i = 0; i < ops_size; ++i)
|
||||||
if (ops[i])
|
if (ops[i])
|
||||||
poperand_free(ops[i]);
|
poperand_free(ops[i]);
|
||||||
free(ops);
|
|
||||||
plabel_free(labels);
|
plabel_free(labels);
|
||||||
free(ident);
|
free(ident);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
-pedantic
|
-pedantic
|
||||||
-pedantic-errors
|
-pedantic-errors
|
||||||
-Wno-unused-variable
|
-Wno-unused-variable
|
||||||
# -Wno-unused-parameter
|
-Wno-unused-parameter
|
||||||
# -Wno-unused-function
|
# -Wno-unused-function
|
||||||
-I.
|
-I.
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
start:
|
start:
|
||||||
; rsp points *at* the top element
|
; rsp points *at* the top element
|
||||||
mov rbp, 2048
|
mov Rbp, 2048
|
||||||
mov rsp, 2048 - 2
|
mov rsp, 2048 - 2
|
||||||
|
|
||||||
lit interrupt_table
|
lit interrupt_table
|
||||||
@ -25,22 +25,12 @@ interrupt_table:
|
|||||||
|
|
||||||
keyboard_interrupt:
|
keyboard_interrupt:
|
||||||
and rfl, rfl, !(1 << Fl_Int)
|
and rfl, rfl, !(1 << 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, Device_Keyboard
|
in r0, Device_Keyboard
|
||||||
|
|
||||||
@ -62,7 +52,7 @@ keyboard_interrupt:
|
|||||||
jmp .L3
|
jmp .L3
|
||||||
|
|
||||||
.L0:
|
.L0:
|
||||||
mov R0, ' '
|
mov R0, 32 ; ' '
|
||||||
call put_char
|
call put_char
|
||||||
jmp .L4
|
jmp .L4
|
||||||
|
|
||||||
@ -90,42 +80,26 @@ keyboard_interrupt:
|
|||||||
jmp .L4
|
jmp .L4
|
||||||
|
|
||||||
.L3:
|
.L3:
|
||||||
add r0, r0, 'A' - 4
|
; add r0, r0, 'A' - 4
|
||||||
call put_char
|
call put_char
|
||||||
jmp .L4
|
jmp .L4
|
||||||
|
|
||||||
.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 << Fl_Int
|
or rfl, rfl, 1 << Fl_Int
|
||||||
iret
|
iret
|
||||||
|
|
||||||
put_char:
|
put_char:
|
||||||
; push rbp
|
push rbp
|
||||||
add rsp, rsp, 2
|
|
||||||
mov u16 [rsp], rbp
|
|
||||||
mov rbp, rsp
|
mov rbp, rsp
|
||||||
; push r1
|
push r1
|
||||||
add rsp, rsp, 2
|
push r2
|
||||||
mov u16 [rsp], r1
|
|
||||||
; push r2
|
|
||||||
add rsp, rsp, 2
|
|
||||||
mov u16 [rsp], r2
|
|
||||||
|
|
||||||
mov r2, screen_y
|
mov r2, screen_y
|
||||||
mul r2, r2, vcd_width_in_ch
|
mul r2, r2, vcd_width_in_ch
|
||||||
@ -152,16 +126,10 @@ put_char:
|
|||||||
mov screen_x, r1
|
mov 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:
|
||||||
|
@ -203,7 +203,7 @@ void write_program(FILE* fp)
|
|||||||
|
|
||||||
printf("assembling program...\n");
|
printf("assembling program...\n");
|
||||||
uint16_t program_size
|
uint16_t program_size
|
||||||
= assemble_lines_with_labels(program, program_asm, program_asm_size);
|
= assemble_to_binary(program, program_asm, program_asm_size);
|
||||||
printf("done!\n");
|
printf("done!\n");
|
||||||
printf("program size = %d\n", program_size);
|
printf("program size = %d\n", program_size);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user