#define MSB24 2
#define MSB32 3
+static char *MOVB="mov.b";
+static char *MOVW="mov.w";
+static char *MOVCB="movc.b";
+static char *MOVCW="movc.w";
+
void bailOut (char *mesg) {
fprintf (stderr, "%s: bailing out\n", mesg);
exit (1);
char *getStackOffset(int stack) {
static char gsoBuf[1024];
- sprintf (gsoBuf, "r7%+d+0%+d%+d", stack,
+ // dit slaat natuurlijk nergens op
+ sprintf (gsoBuf, "r7+(%+d+0%+d%+d)", stack,
FUNC_ISISR(currFunc->type) ?
port->stack.isr_overhead : port->stack.call_overhead,
_G.nRegsSaved);
}
/*-----------------------------------------------------------------*/
-/* toBoolean - return bit for operand!=0 */
+/* toBoolean - return carry for operand!=0 */
/*-----------------------------------------------------------------*/
static char *toBoolean (operand * op) {
switch (AOP_SIZE(op))
case 1:
case 2:
emitcode ("cmp", "%s,#0", AOP_NAME(op));
- return "z";
+ emitcode ("mov", "c,z");
+ return "c";
}
bailOut("toBoolean: unknown size");
}
/*-----------------------------------------------------------------*/
-/* genGoto - generates a ljmp */
+/* genGoto - generates a jmp */
/*-----------------------------------------------------------------*/
static void genGoto (iCode * ic) {
emitcode (";", "genGoto %s", IC_LABEL(ic)->name);
- emitcode ("ljmp", "%05d$", (IC_LABEL (ic)->key + 100));
+ emitcode ("jmp", "%05d$", (IC_LABEL (ic)->key + 100));
}
/*-----------------------------------------------------------------*/
/* genPointerGet - generate code for pointer get */
/*-----------------------------------------------------------------*/
static void genPointerGet (iCode * ic, iCode *pi) {
- char *instr="mov";
+ char *instr;
operand *result=IC_RESULT(ic), *left=IC_LEFT(ic);
aopOp(result,TRUE);
if (IS_GENPTR(operandType(left))) {
- emitcode ("INLINE", "_gptrget %s %s = [%s %s]",
+ emitcode (";", "INLINE\t_gptrget ; %s %s = [%s %s]",
AOP_NAME(result)[0], AOP_NAME(result)[1],
AOP_NAME(left)[0], AOP_NAME(left)[1]);
return;
switch (AOP_TYPE(left))
{
case AOP_CODE:
- instr="movc";
- // fall through
+ if (AOP_SIZE(result)==1) {
+ instr=MOVCB;
+ } else {
+ instr=MOVCW;
+ }
+ emitcode (instr, "%s,[%s]", AOP_NAME(result)[0], AOP_NAME(left)[0]);
+ if (AOP_SIZE(result) > 2) {
+ if (AOP_SIZE(result)==3) {
+ instr=MOVCB;
+ } else {
+ instr=MOVCW;
+ }
+ emitcode (instr, "%s,[%s+2]", AOP_NAME(result)[1], AOP_NAME(left)[0]);
+ }
+ return;
case AOP_FAR:
+ if (AOP_SIZE(result)==1) {
+ instr=MOVB;
+ } else {
+ instr=MOVW;
+ }
emitcode (instr, "%s,[%s]", AOP_NAME(result)[0], AOP_NAME(left)[0]);
if (AOP_SIZE(result) > 2) {
+ if (AOP_SIZE(result)==3) {
+ instr=MOVB;
+ } else {
+ instr=MOVW;
+ }
emitcode (instr, "%s,[%s+2]", AOP_NAME(result)[1], AOP_NAME(left)[0]);
}
return;
case AOP_REG:
emitcode (instr, "%s,[%s]", AOP_NAME(result)[0], AOP_NAME(left)[0]);
if (AOP_SIZE(result) > 2) {
- emitcode (instr, "%s,[%s]", AOP_NAME(result)[1], AOP_NAME(left)[1]);
+ // result is generic pointer
+ sym_link *optype=operandType(left);
+ sym_link *opetype=getSpec(optype);
+ if (IS_PTR(optype) && !IS_GENPTR(optype)) {
+ emitcode ("mov.b", "%s,#0x%02x", AOP_NAME(result)[1],
+ PTR_TYPE(SPEC_OCLS(opetype)));
+ } else {
+ emitcode (instr, "%s,[%s]", AOP_NAME(result)[1], AOP_NAME(left)[1]);
+ }
}
return;
case AOP_STK:
- emitcode (instr, "%s,%s", AOP_NAME(result)[0], AOP_NAME(left)[0]);
+ // if both on stack
+ if (AOP_TYPE(result)==AOP_STK) {
+ if (AOP_SIZE(result)==1) {
+ emitcode ("mov", "r0l,%s", AOP_NAME(left)[0]);
+ emitcode ("mov", "%s,r0l", AOP_NAME(result)[0]);
+ } else {
+ emitcode ("mov", "r0,%s", AOP_NAME(left)[0]);
+ emitcode ("mov", "%s,r0", AOP_NAME(result)[0]);
+ }
+ } else {
+ emitcode (instr, "%s,%s", AOP_NAME(result)[0], AOP_NAME(left)[0]);
+ }
if (AOP_SIZE(result) > 2) {
- emitcode (instr, "%s,%s", AOP_NAME(result)[1], AOP_NAME(left)[1]);
+ if (AOP_TYPE(result)==AOP_STK) {
+ if (AOP_SIZE(result)==3) {
+ emitcode ("mov", "r0l,%s", AOP_NAME(left)[1]);
+ emitcode ("mov", "%s,r0l", AOP_NAME(result)[1]);
+ } else {
+ emitcode ("mov", "r0,%s", AOP_NAME(left)[1]);
+ emitcode ("mov", "%s,r0", AOP_NAME(result)[1]);
+ }
+ } else {
+ emitcode (instr, "%s,%s", AOP_NAME(result)[1], AOP_NAME(left)[1]);
+ }
}
return;
}
/* genPointerSet - stores the value into a pointer location */
/*-----------------------------------------------------------------*/
static void genPointerSet (iCode * ic, iCode *pi) {
- char *instr="mov";
+ char *instr;
operand *result=IC_RESULT(ic), *right=IC_RIGHT(ic);
aopOp(result,TRUE);
if (IS_GENPTR(operandType(result))) {
- emitcode ("INLINE", "_gptrset [%s %s]= %s %s",
+ emitcode (";", "INLINE _gptrset ; [%s %s]= %s %s",
AOP_NAME(result)[0], AOP_NAME(result)[1],
AOP_NAME(right)[0], AOP_NAME(right)[1]);
return;
switch (AOP_TYPE(result))
{
- case AOP_CODE:
- instr="movc";
- // fall through
case AOP_REG:
case AOP_DIR:
case AOP_FAR:
case AOP_STK:
+ if (AOP_SIZE(result)==1) {
+ instr=MOVB;
+ } else {
+ instr=MOVW;
+ }
emitcode (instr, "[%s],%s", AOP_NAME(result)[0], AOP_NAME(right)[0]);
if (AOP_SIZE(result) > 2) {
+ if (AOP_SIZE(result)==3) {
+ instr=MOVB;
+ } else {
+ instr=MOVW;
+ }
emitcode (instr, "[%s],%s", AOP_NAME(result)[1], AOP_NAME(right)[1]);
}
return;
- case AOP_GPTR:
}
bailOut ("genPointerSet: unknown pointer");
}
/* genIfx - generate code for Ifx statement */
/*-----------------------------------------------------------------*/
static void genIfx (iCode * ic, iCode * popIc) {
+ char *instr;
bool trueOrFalse;
symbol *jlbl, *tlbl;
operand *cond=IC_COND(ic);
case AOP_FAR:
case AOP_STK:
tlbl=newiTempLabel(NULL);
- emitcode ("cmp", "%s,#0", AOP_NAME(cond)[0]);
+ if (AOP_SIZE(cond)==1) {
+ instr="cmp.b";
+ } else {
+ instr="cmp.w";
+ }
+ emitcode (instr, "%s,#0", AOP_NAME(cond)[0]);
emitcode (trueOrFalse ? "beq" : "bne", "%05d$", tlbl->key+100);
if (AOP_SIZE(cond) > 2) {
- emitcode ("cmp", "%s,#0", AOP_NAME(cond)[1]);
+ if (AOP_SIZE(cond)==3) {
+ instr="cmp.b";
+ } else {
+ instr="cmp.w";
+ }
+ emitcode (instr, "%s,#0", AOP_NAME(cond)[1]);
emitcode (trueOrFalse ? "beq" : "bne", "%05d$", tlbl->key+100);
}
emitcode ("jmp", "%05d$", jlbl->key+100);
aopOp (IC_RESULT(ic),TRUE);
if (isOperandOnStack(left)) {
- aopOp (IC_LEFT(ic),FALSE);
emitcode ("lea", "%s,%s", AOP_NAME(IC_RESULT(ic))[0],
- AOP_NAME(IC_LEFT(ic))[0]);
+ getStackOffset(OP_SYMBOL(left)->stack));
if (AOP_SIZE(IC_RESULT(ic)) > 2) {
// this must be a generic pointer
emitcode ("mov", "%s,#0x01", AOP_NAME(IC_RESULT(ic))[1]);
/*-----------------------------------------------------------------*/
static void genAssign (iCode * ic) {
operand *result=IC_RESULT(ic), *right=IC_RIGHT(ic);
+ int size;
+ char *instr;
printIc ("genAssign", ic, 1,0,1);
aopOp(right, FALSE);
aopOp(result, TRUE);
+ size=AOP_SIZE(result);
if (result->aop->type==AOP_REG ||
right->aop->type==AOP_REG ||
}
/* general case */
- emitcode ("mov", "%s,%s",
+ if (size==1) {
+ instr=MOVB;
+ } else {
+ instr=MOVW;
+ }
+ emitcode (instr, "%s,%s",
result->aop->name[0], right->aop->name[0]);
if (AOP_SIZE(result) > 2) {
- emitcode ("mov", "%s,%s",
+ if (size==3) {
+ instr=MOVB;
+ } else {
+ instr=MOVW;
+ }
+ emitcode (instr, "%s,%s",
result->aop->name[1], right->aop->name[1]);
}
static void
_xa51_genAssemblerPreamble (FILE * of)
{
+ // this needs to be an include file someday
+ fputs ("pswl\tsfr\t0x400\n", of);
+ fputs ("z\tbit\tpswl.0\n", of);
+ fputs ("n\tbit\tpswl.1\n", of);
+ fputs ("v\tbit\tpswl.2\n", of);
+ fputs ("ac\tbit\tpswl.6\n", of);
+ fputs ("cy\tbit\tpswl.7\n", of);
}
/* Generate interrupt vector table. */
/* Generate code to copy XINIT to XISEG */
static void _xa51_genXINIT (FILE * of) {
fprintf (of, "; _xa51_genXINIT() start\n");
- fprintf (of, " mov a,#l_XINIT\n");
- fprintf (of, " orl a,#l_XINIT>>8\n");
- fprintf (of, " jz 00003$\n");
- fprintf (of, " mov a,#s_XINIT\n");
- fprintf (of, " add a,#l_XINIT\n");
- fprintf (of, " mov r1,a\n");
- fprintf (of, " mov a,#s_XINIT>>8\n");
- fprintf (of, " addc a,#l_XINIT>>8\n");
- fprintf (of, " mov r2,a\n");
- fprintf (of, " mov dptr,#s_XINIT\n");
- fprintf (of, " mov r0,#s_XISEG\n");
- fprintf (of, " mov p2,#(s_XISEG >> 8)\n");
- fprintf (of, "00001$: clr a\n");
- fprintf (of, " movc a,@a+dptr\n");
- fprintf (of, " movx @r0,a\n");
- fprintf (of, " inc dptr\n");
- fprintf (of, " inc r0\n");
- fprintf (of, " cjne r0,#0,00002$\n");
- fprintf (of, " inc p2\n");
- fprintf (of, "00002$: mov a,dpl\n");
- fprintf (of, " cjne a,ar1,00001$\n");
- fprintf (of, " mov a,dph\n");
- fprintf (of, " cjne a,ar2,00001$\n");
- fprintf (of, " mov p2,#0xFF\n");
- fprintf (of, "00003$:\n");
+ fprintf (of, " mov r0,#l_XINIT\n");
+ fprintf (of, " beq 00002$\n");
+ fprintf (of, " mov r1,#s_XINIT\n");
+ fprintf (of, " mov r2,#s_XISEG\n");
+ fprintf (of, "00001$ movc r3l,[r1+]\n");
+ fprintf (of, " mov [r2+],r3l\n");
+ fprintf (of, " djnz r0,00001$\n");
+ fprintf (of, "00002$:\n");
fprintf (of, "; _xa51_genXINIT() end\n");
}
/* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */
static const char *_asmCmd[] =
{
- "xa_asm", "$l", "$3", "$1.asm", NULL
+ "xa_asm", "$l", "$3", "$1.xa", NULL
};
/* Globals */
{
_asmCmd,
NULL,
- "-plosgffc", /* Options with debug */
- "-plosgff", /* Options without debug */
+ "", /* Options with debug */
+ "", /* Options without debug */
0,
- ".asm",
+ ".xa",
NULL /* no do_assemble function */
},
{