Skip to content

Commit

Permalink
Updated code generator to eliminate all x86 output. Preparing to use …
Browse files Browse the repository at this point in the history
…IP-relative addressing mode to support indirect addressing of operands instead of using stack-relative indirect addressing mode.
  • Loading branch information
MorrisMA committed Aug 18, 2017
1 parent 2addcba commit ffa529e
Show file tree
Hide file tree
Showing 20 changed files with 2,759 additions and 2,372 deletions.
Binary file modified PC65/Debug/PC65
Binary file not shown.
3 changes: 2 additions & 1 deletion PC65/src/decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,8 @@ void var_declarations(SYMTAB_NODE_PTR rtn_idp)
{
var_or_field_declarations(rtn_idp,
NULL,
(rtn_idp->defn.key == PROC_DEFN) ? PROC_LOCALS_STACK_FRAME_OFFSET : FUNC_LOCALS_STACK_FRAME_OFFSET);
(rtn_idp->defn.key == PROC_DEFN) ? PROC_LOCALS_STACK_FRAME_OFFSET
: FUNC_LOCALS_STACK_FRAME_OFFSET);
}

/*--------------------------------------------------------------*/
Expand Down
235 changes: 2 additions & 233 deletions PC65/src/emitasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,63 +33,7 @@

int label_index = 0;

char asm_buffer[MAX_PRINT_LINE_LENGTH]; // assembly stmt buffer //
char *asm_bufferp = asm_buffer; // ptr into asm buffer //

char *register_strings[] = {
"ax",
"ah",
"al",
"bx",
"bh",
"bl",
"cx",
"ch",
"cl",
"dx",
"dh",
"dl",
"cs",
"ds",
"es",
"ss",
"sp",
"bp",
"si",
"di",
};

char *instruction_strings[] = {
"mov\t",
"rep\tmovsb",
"lea\t",
"xchg",
"cmp\t",
"repe\tcmpsb",
"pop\t",
"push",
"and\t",
"or\t",
"xor\t",
"neg\t",
"inc\t",
"dec\t",
"add\t",
"sub\t",
"imul",
"idiv",
"cld",
"call",
"ret\t",
"jmp\t",
"jl\t",
"jle\t",
"je\t",
"jne\t",
"jge\t",
"jg\t",
"cwd\t",
};
extern FILE *code_file;

//**********************************************//
// //
Expand All @@ -106,181 +50,6 @@ char *instruction_strings[] = {

void label(char *prefix, int index)
{
sprintf(asm_bufferp, "%s_%03d", prefix, index);
advance_asm_bufferp();
}

//////////////////////////////////////////////////////////////////
// word_label Write a word label constructed from //
// the prefix and the label index. //
// //
// Example: WORD PTR $F_007 //
//////////////////////////////////////////////////////////////////

void word_label(char *prefix, int index)
{
sprintf(asm_bufferp, "WORD PTR %s_%03d", prefix, index);
advance_asm_bufferp();
}

//////////////////////////////////////////////////////////////////
// high_dword_label Write a word label constructed from //
// the prefix and the label index and //
// offset by 2 to point to the high word //
// of a double word. //
// //
// Example: WORD PTR $F_007+2 //
//////////////////////////////////////////////////////////////////

void high_dword_label(char *prefix, int index)
{
sprintf(asm_bufferp, "WORD PTR %s_%03d+2", prefix, index);
advance_asm_bufferp();
}

//////////////////////////////////////////////////////////////////
// reg Write a register name. Example: ax //
//////////////////////////////////////////////////////////////////

void reg(REGISTER r)
{
sprintf(asm_bufferp, "%s", register_strings[r]);
advance_asm_bufferp();
}

//////////////////////////////////////////////////////////////////
// operator Write an opcode. Example: add //
//////////////////////////////////////////////////////////////////

void _operator(INSTRUCTION opcode)
{
sprintf(asm_bufferp, "\t%s", instruction_strings[opcode]);
advance_asm_bufferp();
}

//////////////////////////////////////////////////////////////////
// byte Write a byte label constructed from //
// the id name and its label index. //
// //
// Example: BYTE PTR ch_007 //
//////////////////////////////////////////////////////////////////

void byte(SYMTAB_NODE_PTR idp)
{
sprintf(asm_bufferp, "BYTE PTR %s_%03d", idp->name, idp->label_index);
advance_asm_bufferp();
}

//////////////////////////////////////////////////////////////////
// byte_indirect Write an indirect reference to a byte //
// via a register. //
// //
// Example: BYTE PTR [bx] //
//////////////////////////////////////////////////////////////////

void byte_indirect(REGISTER r)
{
sprintf(asm_bufferp, "BYTE PTR [%s]", register_strings[r]);
advance_asm_bufferp();
}

//////////////////////////////////////////////////////////////////
// word Write a word label constructed from //
// the id name and its label index. //
// //
// Example: WORD PTR sum_007 //
//////////////////////////////////////////////////////////////////

void word(SYMTAB_NODE_PTR idp)
{
sprintf(asm_bufferp, "WORD PTR %s_%03d", idp->name, idp->label_index);
advance_asm_bufferp();
}

//////////////////////////////////////////////////////////////////
// high_dword Write a word label constructed from //
// the id name and its label index and //
// offset by 2 to point to the high word //
// of a double word. //
// //
// Example: WORD PTR sum_007+2 //
//////////////////////////////////////////////////////////////////

void high_dword(SYMTAB_NODE_PTR idp)
{
sprintf(asm_bufferp, "WORD PTR %s_%03d+2", idp->name, idp->label_index);
advance_asm_bufferp();
}

//////////////////////////////////////////////////////////////////
// word_indirect Write an indirect reference to a word //
// via a register. //
// //
// Example: WORD PTR [bx] //
//////////////////////////////////////////////////////////////////

void word_indirect(REGISTER r)
{
sprintf(asm_bufferp, "WORD PTR [%s]", register_strings[r]);
advance_asm_bufferp();
}

//////////////////////////////////////////////////////////////////
// high_dword_indirect Write an indirect reference to the //
// high word of a double word via a //
// register. //
// //
// Example: WORD PTR [bx+2] //
//////////////////////////////////////////////////////////////////

void high_dword_indirect(REGISTER r)
{
sprintf(asm_bufferp, "WORD PTR [%s+2]", register_strings[r]);
advance_asm_bufferp();
}

//////////////////////////////////////////////////////////////////
// tagged_name Write an id name tagged with the id's //
// label index. //
// //
// Example: x_007 //
//////////////////////////////////////////////////////////////////

void tagged_name(SYMTAB_NODE_PTR idp)
{
sprintf(asm_bufferp, "%s_%03d", idp->name, idp->label_index);
advance_asm_bufferp();
}

//////////////////////////////////////////////////////////////////
// name_lit Write a literal name. //
// //
// Example: _float_convert //
//////////////////////////////////////////////////////////////////

void name_lit(char *name)
{
sprintf(asm_bufferp, "%s", name);
advance_asm_bufferp();
}

//////////////////////////////////////////////////////////////////
// integer_lit Write an integer as a string. //
//////////////////////////////////////////////////////////////////

void integer_lit(int n)
{
sprintf(asm_bufferp, "%d", n);
advance_asm_bufferp();
fprintf(code_file, "%s_%03d\n", prefix, index);
}

//////////////////////////////////////////////////////////////////
// char_lit Write a character surrounded by single //
// quotes. //
//////////////////////////////////////////////////////////////////

void char_lit(char ch)
{
sprintf(asm_bufferp, "'%c'", ch);
advance_asm_bufferp();
}
Loading

0 comments on commit ffa529e

Please sign in to comment.