+ /* save the signs of the operands */
+ if (AOP_TYPE(right) == AOP_LIT)
+ {
+ signed char val = (char) floatFromVal (AOP (right)->aopu.aop_lit);
+
+ if (!rUnsigned && val < 0)
+ emitcode ("mov", "b,#!constbyte", -val);
+ else
+ emitcode ("mov", "b,#!constbyte", (unsigned char) val);
+ }
+ else /* ! literal */
+ {
+ if (rUnsigned) /* emitcode (";", "signed"); */
+ emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE, NULL));
+ else
+ {
+ MOVA (aopGet (right, 0, FALSE, FALSE, NULL));
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,!tlabel", lbl->key + 100);
+ emitcode ("cpl", "F0"); /* complement sign flag */
+ emitcode ("cpl", "a"); /* 2's complement */
+ emitcode ("inc", "a");
+ emitLabel (lbl);
+ emitcode ("mov", "b,a");
+ }
+ }
+
+ if (AOP_TYPE(left) == AOP_LIT)
+ {
+ signed char val = (char) floatFromVal (AOP (left)->aopu.aop_lit);
+
+ if (!lUnsigned && val < 0)
+ emitcode ("mov", "a,#!constbyte", -val);
+ else
+ emitcode ("mov", "a,#!constbyte", (unsigned char) val);
+ }
+ else /* ! literal */
+ {
+ MOVA (aopGet (left, 0, FALSE, FALSE, NULL));
+
+ if (!lUnsigned) /* emitcode (";", "signed"); */
+ {
+ lbl = newiTempLabel (NULL);
+ emitcode ("jnb", "acc.7,!tlabel", lbl->key + 100);
+ emitcode ("cpl", "F0"); /* complement sign flag */
+ emitcode ("cpl", "a"); /* 2's complement */
+ emitcode ("inc", "a");
+ emitLabel (lbl);
+ }
+ }
+
+ /* now the multiplication */
+ emitcode ("mul", "ab");
+ _G.accInUse++;
+ aopOp(result, ic, TRUE, FALSE);
+ 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",
+ size, __FILE__, lineno);
+ exit (1);
+ }
+
+ if (runtimeSign || compiletimeSign)
+ {
+ lbl = newiTempLabel (NULL);
+ if (runtimeSign)
+ emitcode ("jnb", "F0,!tlabel", lbl->key + 100);
+ emitcode ("cpl", "a"); /* lsb 2's complement */
+ if (size != 2)
+ emitcode ("inc", "a"); /* inc doesn't set carry flag */
+ else
+ {
+ emitcode ("add", "a,#1"); /* this sets carry flag */
+ emitcode ("xch", "a,b");
+ emitcode ("cpl", "a"); /* msb 2's complement */
+ emitcode ("addc", "a,#0");
+ emitcode ("xch", "a,b");
+ }
+ emitLabel (lbl);
+ }
+ aopPut (result, "a", 0);
+ _G.accInUse--;
+ if (size == 2)
+ aopPut (result, "b", 1);
+
+ popB (pushedB);
+}
+
+/*-----------------------------------------------------------------*/
+/* genMultTwoByte - use the DS390 MAC unit to do 16*16 multiply */
+/*-----------------------------------------------------------------*/
+static void genMultTwoByte (operand *left, operand *right,
+ operand *result, iCode *ic)
+{
+ sym_link *retype = getSpec(operandType(right));
+ sym_link *letype = getSpec(operandType(left));
+ int umult = SPEC_USIGN(retype) | SPEC_USIGN(letype);
+ symbol *lbl;
+
+ if (AOP_TYPE (left) == AOP_LIT) {
+ operand *t = right;
+ right = left;
+ left = t;
+ }
+ /* save EA bit in F1 */
+ lbl = newiTempLabel(NULL);
+ emitcode ("setb","F1");
+ emitcode ("jbc","EA,!tlabel",lbl->key+100);
+ emitcode ("clr","F1");
+ emitLabel (lbl);
+
+ /* load up MB with right */
+ if (!umult) {
+ emitcode("clr","F0");
+ if (AOP_TYPE(right) == AOP_LIT) {
+ int val=(int)floatFromVal (AOP (right)->aopu.aop_lit);
+ if (val < 0) {
+ emitcode("setb","F0");
+ val = -val;
+ }
+ emitcode ("mov","mb,#!constbyte",val & 0xff);
+ emitcode ("mov","mb,#!constbyte",(val >> 8) & 0xff);
+ } else {
+ lbl = newiTempLabel(NULL);
+ emitcode ("mov","b,%s",aopGet(right,0,FALSE,FALSE,NULL));
+ emitcode ("mov","a,%s",aopGet(right,1,FALSE,FALSE,NULL));
+ emitcode ("jnb","acc.7,!tlabel",lbl->key+100);
+ emitcode ("xch", "a,b");
+ emitcode ("cpl","a");
+ emitcode ("add", "a,#1");
+ emitcode ("xch", "a,b");
+ emitcode ("cpl", "a"); // msb
+ emitcode ("addc", "a,#0");
+ emitcode ("setb","F0");
+ emitLabel (lbl);
+ emitcode ("mov","mb,b");
+ emitcode ("mov","mb,a");
+ }
+ } else {
+ emitcode ("mov","mb,%s",aopGet(right,0,FALSE,FALSE,NULL));
+ emitcode ("mov","mb,%s",aopGet(right,1,FALSE,FALSE,NULL));
+ }
+ /* load up MA with left */
+ if (!umult) {
+ lbl = newiTempLabel(NULL);
+ emitcode ("mov","b,%s",aopGet(left,0,FALSE,FALSE,NULL));
+ emitcode ("mov","a,%s",aopGet(left,1,FALSE,FALSE,NULL));
+ emitcode ("jnb","acc.7,!tlabel",lbl->key+100);
+ emitcode ("xch", "a,b");
+ emitcode ("cpl","a");
+ emitcode ("add", "a,#1");
+ emitcode ("xch", "a,b");
+ emitcode ("cpl", "a"); // msb
+ emitcode ("addc","a,#0");
+ emitcode ("jbc","F0,!tlabel",lbl->key+100);
+ emitcode ("setb","F0");
+ emitLabel (lbl);
+ emitcode ("mov","ma,b");
+ emitcode ("mov","ma,a");
+ } else {
+ emitcode ("mov","ma,%s",aopGet(left,0,FALSE,FALSE,NULL));
+ emitcode ("mov","ma,%s",aopGet(left,1,FALSE,FALSE,NULL));
+ }
+ /* wait for multiplication to finish */
+ lbl = newiTempLabel(NULL);
+ emitLabel (lbl);
+ emitcode("mov","a,mcnt1");
+ emitcode("anl","a,#!constbyte",0x80);
+ emitcode("jnz","!tlabel",lbl->key+100);
+
+ freeAsmop (left, NULL, ic, TRUE);
+ freeAsmop (right, NULL, ic,TRUE);
+ aopOp(result, ic, TRUE, FALSE);
+
+ /* if unsigned then simple */
+ if (umult) {
+ emitcode ("mov","a,ma");
+ if (AOP_SIZE(result) >= 4) aopPut(result,"a",3);
+ emitcode ("mov","a,ma");
+ if (AOP_SIZE(result) >= 3) aopPut(result,"a",2);
+ aopPut(result,"ma",1);
+ aopPut(result,"ma",0);
+ } else {
+ emitcode("push","ma");
+ emitcode("push","ma");
+ emitcode("push","ma");
+ MOVA("ma");
+ /* negate result if needed */
+ lbl = newiTempLabel(NULL);
+ emitcode("jnb","F0,!tlabel",lbl->key+100);
+ emitcode("cpl","a");
+ emitcode("add","a,#1");
+ emitLabel (lbl);
+ if (AOP_TYPE(result) == AOP_ACC)
+ {
+ D (emitcode(";", "ACC special case."));
+ /* We know result is the only live aop, and
+ * it's obviously not a DPTR2, so AP is available.
+ */
+ emitcode("mov", "%s,acc", DP2_RESULT_REG);
+ }
+ else
+ {
+ aopPut(result,"a",0);
+ }
+
+ emitcode("pop","acc");
+ lbl = newiTempLabel(NULL);
+ emitcode("jnb","F0,!tlabel",lbl->key+100);
+ emitcode("cpl","a");
+ emitcode("addc","a,#0");
+ emitLabel (lbl);
+ aopPut(result,"a",1);
+ emitcode("pop","acc");
+ if (AOP_SIZE(result) >= 3) {
+ lbl = newiTempLabel(NULL);
+ emitcode("jnb","F0,!tlabel",lbl->key+100);
+ emitcode("cpl","a");
+ emitcode("addc","a,#0");
+ emitLabel (lbl);
+ aopPut(result,"a",2);
+ }
+ emitcode("pop","acc");
+ if (AOP_SIZE(result) >= 4) {
+ lbl = newiTempLabel(NULL);
+ emitcode("jnb","F0,!tlabel",lbl->key+100);
+ emitcode("cpl","a");
+ emitcode("addc","a,#0");
+ emitLabel (lbl);
+ aopPut(result,"a",3);
+ }
+ if (AOP_TYPE(result) == AOP_ACC)
+ {
+ /* We stashed the result away above. */
+ emitcode("mov", "acc,%s", DP2_RESULT_REG);
+ }
+
+ }
+ freeAsmop (result, NULL, ic, TRUE);
+
+ /* restore EA bit in F1 */
+ lbl = newiTempLabel(NULL);
+ emitcode ("jnb","F1,!tlabel",lbl->key+100);
+ emitcode ("setb","EA");
+ emitLabel (lbl);
+ return ;
+}
+
+/*-----------------------------------------------------------------*/
+/* genMult - generates code for multiplication */
+/*-----------------------------------------------------------------*/
+static void
+genMult (iCode * ic)
+{
+ operand *left = IC_LEFT (ic);
+ operand *right = IC_RIGHT (ic);
+ operand *result = IC_RESULT (ic);
+
+ D (emitcode (";", "genMult"));
+
+ /* assign the asmops */
+ 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, ic);
+ goto release;
+ }
+
+ /* if both are of size == 1 */
+ if (AOP_SIZE (left) == 1 &&
+ AOP_SIZE (right) == 1)
+ {
+ genMultOneByte (left, right, result, ic);
+ goto release;
+ }
+
+ if (AOP_SIZE (left) == 2 && AOP_SIZE(right) == 2) {
+ /* use the ds390 ARITHMETIC accel UNIT */
+ genMultTwoByte (left, right, result, ic);
+ return ;
+ }
+ /* should have been converted to function call */
+ assert (0);
+
+release:
+ freeAsmop (result, NULL, ic, TRUE);
+ freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+ freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
+}