static void
genMultbits (operand * left,
operand * right,
- operand * result)
+ operand * result,
+ iCode * ic)
{
emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir);
+ aopOp(result, ic, TRUE, FALSE);
outBitC (result);
}
static void
genMultOneByte (operand * left,
operand * right,
- operand * result)
+ operand * result,
+ iCode * ic)
{
sym_link *opetype = operandType (result);
symbol *lbl;
- int size=AOP_SIZE(result);
- if (size<1 || size>2) {
- // this should never happen
- fprintf (stderr, "size!=1||2 (%d) in %s at line:%d \n",
- AOP_SIZE(result), __FILE__, lineno);
- exit (1);
- }
/* (if two literals: the value is computed before) */
/* if one literal, literal on the right */
emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE, TRUE));
MOVA (aopGet (AOP (left), 0, FALSE, FALSE, TRUE));
emitcode ("mul", "ab");
+
+ _G.accInUse++;
+ aopOp(result, ic, TRUE, FALSE);
+
+ if (AOP_SIZE(result)<1 || AOP_SIZE(result)>2)
+ {
+ // this should never happen
+ fprintf (stderr, "size!=1||2 (%d) in %s at line:%d \n",
+ AOP_SIZE(result), __FILE__, lineno);
+ exit (1);
+ }
+
aopPut (AOP (result), "a", 0);
- if (size==2) {
+ _G.accInUse--;
+ if (AOP_SIZE(result)==2)
+ {
aopPut (AOP (result), "b", 1);
}
return;
}
emitcode ("mul", "ab");
+ _G.accInUse++;
+ aopOp(result, ic, TRUE, FALSE);
+
+ if (AOP_SIZE(result)<1 || AOP_SIZE(result)>2)
+ {
+ // this should never happen
+ fprintf (stderr, "size!=1||2 (%d) in %s at line:%d \n",
+ AOP_SIZE(result), __FILE__, lineno);
+ exit (1);
+ }
+
lbl=newiTempLabel(NULL);
emitcode ("jnb", "F0,%05d$", lbl->key+100);
// only ONE op was negative, we have to do a 8/16-bit two's complement
emitcode ("cpl", "a"); // lsb
- if (size==1) {
+ if (AOP_SIZE(result)==1) {
emitcode ("inc", "a");
} else {
emitcode ("add", "a,#1");
emitcode ("", "%05d$:", lbl->key+100);
aopPut (AOP (result), "a", 0);
- if (size==2) {
+ _G.accInUse--;
+ if (AOP_SIZE(result)==2) {
aopPut (AOP (result), "b", 1);
}
}
D (emitcode (";", "genMult "););
/* assign the amsops */
- AOP_OP_3 (ic);
+ AOP_OP_2 (ic);
/* special cases first */
/* both are bits */
if (AOP_TYPE (left) == AOP_CRY &&
AOP_TYPE (right) == AOP_CRY)
{
- genMultbits (left, right, result);
+ genMultbits (left, right, result, ic);
goto release;
}
if (AOP_SIZE (left) == 1 &&
AOP_SIZE (right) == 1)
{
- genMultOneByte (left, right, result);
+ genMultOneByte (left, right, result, ic);
goto release;
}
static void
genDivbits (operand * left,
operand * right,
- operand * result)
+ operand * result,
+ iCode * ic)
{
char *l;
LOAD_AB_FOR_DIV (left, right, l);
emitcode ("div", "ab");
emitcode ("rrc", "a");
+ aopOp(result, ic, TRUE, FALSE);
+
aopPut (AOP (result), "c", 0);
}
static void
genDivOneByte (operand * left,
operand * right,
- operand * result)
+ operand * result,
+ iCode * ic)
{
sym_link *opetype = operandType (result);
char *l;
symbol *lbl;
int size, offset;
- size = AOP_SIZE (result) - 1;
offset = 1;
/* signed or unsigned */
if (SPEC_USIGN (opetype))
{
- /* unsigned is easy */
- LOAD_AB_FOR_DIV (left, right, l);
- emitcode ("div", "ab");
- aopPut (AOP (result), "a", 0);
- while (size--)
- aopPut (AOP (result), zero, offset++);
+ /* unsigned is easy */
+ LOAD_AB_FOR_DIV (left, right, l);
+ emitcode ("div", "ab");
+
+ _G.accInUse++;
+ aopOp(result, ic, TRUE, FALSE);
+ aopPut (AOP (result), "a", 0);
+ _G.accInUse--;
+
+ size = AOP_SIZE (result) - 1;
+
+ while (size--)
+ {
+ aopPut (AOP (result), zero, offset++);
+ }
return;
}
emitcode ("", "%05d$:", (lbl->key + 100));
/* now we are done */
- aopPut (AOP (result), "b", 0);
- if (size > 0)
+ _G.accInUse++;
+ aopOp(result, ic, TRUE, FALSE);
+
+ aopPut (AOP (result), "b", 0);
+
+ size = AOP_SIZE (result) - 1;
+
+ if (size > 0)
{
emitcode ("mov", "c,b.7");
emitcode ("subb", "a,acc");
}
- while (size--)
- aopPut (AOP (result), "a", offset++);
+ while (size--)
+ {
+ aopPut (AOP (result), "a", offset++);
+ }
+ _G.accInUse--;
}
operand *right = IC_RIGHT (ic);
operand *result = IC_RESULT (ic);
- D (emitcode (";", "genDiv ");
- );
+ D (emitcode (";", "genDiv "););
/* assign the amsops */
- AOP_OP_3 (ic);
+ AOP_OP_2 (ic);
/* special cases first */
/* both are bits */
if (AOP_TYPE (left) == AOP_CRY &&
AOP_TYPE (right) == AOP_CRY)
{
- genDivbits (left, right, result);
+ genDivbits (left, right, result, ic);
goto release;
}
if (AOP_SIZE (left) == 1 &&
AOP_SIZE (right) == 1)
{
- genDivOneByte (left, right, result);
+ genDivOneByte (left, right, result, ic);
goto release;
}
then don't need anything more */
if (!AOP_INPREG (AOP (result)))
{
- /* otherwise get a free pointer register */
- aop = newAsmop (0);
- preg = getFreePtr (ic, &aop, FALSE);
- emitcode ("mov", "%s,%s",
- preg->name,
- aopGet (AOP (result), 0, FALSE, TRUE));
- rname = preg->name;
+ if (
+ //AOP_TYPE (result) == AOP_STK
+ IS_AOP_PREG(result)
+ )
+ {
+ // Aha, it is a pointer, just in disguise.
+ rname = aopGet (AOP (result), 0, FALSE, FALSE);
+ if (*rname != '@')
+ {
+ fprintf(stderr, "probable internal error: unexpected rname @ %s:%d\n",
+ __FILE__, __LINE__);
+ }
+ else
+ {
+ // Expected case.
+ rname++; // skip the '@'.
+ }
+ }
+ else
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (result), 0, FALSE, TRUE));
+ rname = preg->name;
+ }
+ }
+ else
+ {
+ rname = aopGet (AOP (result), 0, FALSE, FALSE);
}
- else
- rname = aopGet (AOP (result), 0, FALSE, FALSE);
aopOp (right, ic, FALSE);
-
+
/* if bitfield then unpack the bits */
if (IS_BITVAR (retype) || IS_BITVAR (letype))
genPackBits ((IS_BITVAR (retype) ? retype : letype), right, rname, POINTER);