diff --git a/gen.c b/gen.c index 0e130a5..71fb848 100644 --- a/gen.c +++ b/gen.c @@ -992,13 +992,13 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file // Convert operator name to instruction name if(curtok->subtype==LADD) - sprintf(operator,"addl"); + sprintf(operator,"%s",gen->ld.add_32); else if(curtok->subtype==LSMINUS) - sprintf(operator,"subl"); + sprintf(operator,"%s",gen->ld.sub_32); else if(curtok->subtype==LSMUL) - sprintf(operator,"imull"); + sprintf(operator,"%s",gen->ld.mul_32); else if(curtok->subtype==LSDIV) - sprintf(operator,"idivl"); + sprintf(operator,"%s",gen->ld.div_32); else if(curtok->subtype==LASSIGN) sprintf(operator,"%s",gen->ld.mov_32); else if(curtok->subtype==LSREF) @@ -1306,7 +1306,7 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file case LSMINUS: opos+=sprintf(output_buffer+opos,"\t%s %s,%%%s\n",gen->ld.mov_32,operands[0],gen->ld.scratch1_32); opos+=sprintf(output_buffer+opos,"\t%s %s,%s\n",gen->ld.mov_32,operands[1],operands[0]); - opos+=sprintf(output_buffer+opos,"\tsubl %%%s,%s\n",gen->ld.scratch1_32,operands[0]); + opos+=sprintf(output_buffer+opos,"\t%s %%%s,%s\n",gen->ld.sub_32,gen->ld.scratch1_32,operands[0]); break; case LSMUL: diff --git a/gen.h b/gen.h index 3d7954a..a6c0c2c 100644 --- a/gen.h +++ b/gen.h @@ -18,10 +18,16 @@ typedef struct LangDef { const char*acc_32; const char*acc_wordsize; + const char*add_32; + const char*add_wordsize; const char*bp; + const char*div_32; + const char*div_wordsize; const char*lea_wordsize; const char*mov_32; const char*mov_wordsize; + const char*mul_32; + const char*mul_wordsize; const char*pop_wordsize; const char*push_wordsize; const char*registers_abi_32[6]; @@ -29,6 +35,7 @@ typedef struct LangDef const char*scratch1_32; const char*scratch1_wordsize; const char*sp; + const char*sub_32; const char*sub_wordsize; }LangDef; diff --git a/i386.c b/i386.c index acc5145..1ce5c63 100644 --- a/i386.c +++ b/i386.c @@ -8,10 +8,16 @@ LangDef gen_i386_langdef(void) LangDef ld={ .acc_32="eax", .acc_wordsize="eax", + .add_32="addl", + .add_wordsize="addl", .bp="ebp", + .div_32="idivl", + .div_wordsize="idivl", .lea_wordsize="leal", .mov_32="movl", .mov_wordsize="movl", + .mul_32="imull", + .mul_wordsize="imull", .pop_wordsize="popl", .push_wordsize="pushl", .registers_abi_32={"edi","esi","edx","ecx","ecx","ecx"}, @@ -19,6 +25,7 @@ LangDef gen_i386_langdef(void) .scratch1_32="ecx", .scratch1_wordsize="ecx", .sp="esp", + .sub_32="subl", .sub_wordsize="subl", }; return ld; diff --git a/x86_64.c b/x86_64.c index 7371461..671570d 100644 --- a/x86_64.c +++ b/x86_64.c @@ -10,10 +10,16 @@ LangDef gen_x86_64_langdef(void) LangDef ld={ .acc_32="eax", .acc_wordsize="rax", + .add_32="addl", + .add_wordsize="addq", .bp="rbp", + .div_32="idivl", + .div_wordsize="idivq", .lea_wordsize="leaq", .mov_32="movl", .mov_wordsize="movq", + .mul_32="imull", + .mul_wordsize="imulq", .pop_wordsize="popq", .push_wordsize="pushq", .registers_abi_32={"edi","esi","edx","ecx","r8d","r9d"}, @@ -21,6 +27,7 @@ LangDef gen_x86_64_langdef(void) .scratch1_32="r8d", .scratch1_wordsize="r8", .sp="rsp", + .sub_32="subl", .sub_wordsize="subq", }; return ld;