#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]);
}