- DEBUGemitcode(";","size %d",size);
-
- switch (lit & 0xff) {
- case 0:
- break;
- case 1:
- if(sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))))
- emitpcode(POC_INCF, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- else {
- know_W = 0;
- emitpcode(POC_INCFW, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- if(AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
- emitpcode(POC_MOVWF, popGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
- }
- break;
- case 0xff:
- if(sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))))
- emitpcode(POC_DECF, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- else {
- know_W = 0;
- emitpcode(POC_DECFW, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- if(AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
- emitpcode(POC_MOVWF, popGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
- }
- break;
- default:
- if( !know_W || ( (lit&0xff) != l1) ) {
- know_W = 1;
- emitpcode(POC_MOVLW,popGetLit(lit&0xff));
- }
- if(sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))))
- emitpcode(POC_ADDWF, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- else {
- know_W = 0;
- emitpcode(POC_ADDFW, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- emitpcode(POC_MOVWF, popGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
- if(size) {
- emitSKPNC;
- emitpcode(POC_INCF, popGet(AOP(IC_LEFT(ic)),offset+1,FALSE,FALSE));
- }
- }
- }
-
- l1 = lit & 0xff;
- lit >>= 8;
- offset++;
- }
-
- } else if(AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
-
- emitcode(";bitadd","right is bit: %s",aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
- emitcode(";bitadd","left is bit: %s",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitcode(";bitadd","result is bit: %s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
-
- /* here we are adding a bit to a char or int */
- if(size == 1) {
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
-
- emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
- emitpcode(POC_INCF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
-
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_RIGHT(ic))->aopu.aop_dir,
- AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode(" incf","%s,f", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- } else {
-
- if(AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
- emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
- emitpcode(POC_XORLW , popGetLit(1));
-
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_RIGHT(ic))->aopu.aop_dir,
- AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode(" xorlw","1");
- } else {
- emitpcode(POC_MOVFW , popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
- emitpcode(POC_INCFW , popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
-
- emitcode("movf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_RIGHT(ic))->aopu.aop_dir,
- AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode(" incf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- }
-
- if(AOP_TYPE(IC_RESULT(ic)) != AOP_ACC) {
-
- if(AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) {
- emitpcode(POC_ANDLW , popGetLit(1));
- emitpcode(POC_BCF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- emitSKPZ;
- emitpcode(POC_BSF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
-/*
- emitcode("andlw","1");
- emitcode("bcf","(%s >> 3), (%s & 7)",
- AOP(IC_RESULT(ic))->aopu.aop_dir,
- AOP(IC_RESULT(ic))->aopu.aop_dir);
- emitSKPZ;
- emitcode("bsf","(%s >> 3), (%s & 7)",
- AOP(IC_RESULT(ic))->aopu.aop_dir,
- AOP(IC_RESULT(ic))->aopu.aop_dir);
-*/
-
- } else {
- emitpcode(POC_MOVWF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- }
- }
- }
-
- } else {
- int offset = 1;
-
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
- emitCLRZ;
- emitpcode(POC_BTFSC, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
- emitpcode(POC_INCF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
-
- emitcode("clrz","");
-
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_RIGHT(ic))->aopu.aop_dir,
- AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode(" incf","%s,f", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
-
- } else {
-
- emitpcode(POC_MOVFW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitpcode(POC_BTFSC, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
- emitpcode(POC_INCFW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitpcode(POC_MOVWF, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
-
-
- emitcode("movf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(IC_RIGHT(ic))->aopu.aop_dir,
- AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode(" incf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
-
- }
-
- while(--size){
- emitSKPZ;
- emitpcode(POC_INCF, popGet(AOP(IC_RESULT(ic)),offset++,FALSE,FALSE));
- //emitcode(" incf","%s,f", aopGet(AOP(IC_RIGHT(ic)),offset++,FALSE,FALSE));
- }
-
- }
-
- } else {
-
- if(strcmp(aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE),"a") == 0 ) {
- emitpcode(POC_ADDFW, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
- emitpcode(POC_MOVWF,popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- } else {
-
- if ( AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
- emitpcode(POC_ADDFW, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
- if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
- emitpcode(POC_MOVWF,popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- } else {
-
- emitpcode(POC_MOVFW,popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
-
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) )
- emitpcode(POC_ADDWF, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- else {
- if( (AOP_TYPE(IC_LEFT(ic)) == AOP_IMMD) ||
- (AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ) {
- emitpcode(POC_ADDLW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- } else {
- emitpcode(POC_ADDFW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
- emitpcode(POC_MOVWF,popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- }
- }
- }
- }
-
- offset = 1;
- size--;
-
- while(size--){
- if (!sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
- emitpcode(POC_MOVFW, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- emitpcode(POC_MOVWF, popGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
-
- emitcode("movf","%s,w", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
- emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
- }
-
- emitpcode(POC_MOVFW, popGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- emitSKPNC;
- emitpcode(POC_INCFSZW, popGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- emitpcode(POC_ADDWF, popGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
-
- /*
- emitcode("movf","%s,w", aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- emitSKPNC;
- emitcode("incfsz","%s,w",aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- emitcode("addwf","%s,f", aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
- */
-
- offset++;
- }
-
- }
-
- //adjustArithmeticResult(ic);
-
- release:
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
-}
-
-/*-----------------------------------------------------------------*/
-/* genMinusDec :- does subtraction with decrement if possible */
-/*-----------------------------------------------------------------*/
-static bool genMinusDec (iCode *ic)
-{
- unsigned int icount ;
- unsigned int size = getDataSize(IC_RESULT(ic));
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* will try to generate an increment */
- /* if the right side is not a literal
- we cannot */
- if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
- return FALSE ;
-
- DEBUGemitcode ("; lit val","%d",(unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit));
-
- /* if the literal value of the right hand side
- is greater than 4 then it is not worth it */
- if ((icount = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit)) > 2)
- return FALSE ;
-
- /* if decrement 16 bits in register */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) &&
- (size > 1) &&
- (icount == 1)) {
-
- if(size == 2) {
- emitcode("decf","%s,f",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
- emitcode("incfsz","%s,w",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
- emitcode(" decf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
- } else {
- /* size is 3 or 4 */
- emitcode("movlw","0xff");
- emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
-
- emitSKPNC;
- emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
- emitSKPNC;
- emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE));
-
- if(size > 3) {
- emitcode("skpnc","");
- emitSKPNC;
- emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE));
- }
-
- }
-
- return TRUE;
-
- }
-
- /* if the sizes are greater than 1 then we cannot */
- if (AOP_SIZE(IC_RESULT(ic)) > 1 ||
- AOP_SIZE(IC_LEFT(ic)) > 1 )
- return FALSE ;
-
- /* we can if the aops of the left & result match or
- if they are in registers and the registers are the
- same */
- if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic)))) {
-
- while (icount--)
- emitpcode(POC_DECF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
-
- //emitcode ("decf","%s,f",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
-
- return TRUE ;
- }
-
- DEBUGemitcode ("; returning"," result=%s, left=%s",
- aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),
- aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- if(size==1) {
- emitcode("decf","%s,w",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
- emitcode("movwf","%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
- return TRUE;
- }
-
- return FALSE ;
-}
-
-/*-----------------------------------------------------------------*/
-/* addSign - complete with sign */
-/*-----------------------------------------------------------------*/
-static void addSign(operand *result, int offset, int sign)
-{
- int size = (getDataSize(result) - offset);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(size > 0){
- if(sign){
- emitcode("rlc","a");
- emitcode("subb","a,acc");
- while(size--)
- aopPut(AOP(result),"a",offset++);
- } else
- while(size--)
- aopPut(AOP(result),zero,offset++);
- }
-}
-
-/*-----------------------------------------------------------------*/
-/* genMinusBits - generates code for subtraction of two bits */
-/*-----------------------------------------------------------------*/
-static void genMinusBits (iCode *ic)
-{
- symbol *lbl = newiTempLabel(NULL);
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY){
- emitcode("mov","c,%s",AOP(IC_LEFT(ic))->aopu.aop_dir);
- emitcode("jnb","%s,%05d_DS_",AOP(IC_RIGHT(ic))->aopu.aop_dir,(lbl->key+100));
- emitcode("cpl","c");
- emitcode("","%05d_DS_:",(lbl->key+100));
- outBitC(IC_RESULT(ic));
- }
- else{
- emitcode("mov","c,%s",AOP(IC_RIGHT(ic))->aopu.aop_dir);
- emitcode("subb","a,acc");
- emitcode("jnb","%s,%05d_DS_",AOP(IC_LEFT(ic))->aopu.aop_dir,(lbl->key+100));
- emitcode("inc","a");
- emitcode("","%05d_DS_:",(lbl->key+100));
- aopPut(AOP(IC_RESULT(ic)),"a",0);
- addSign(IC_RESULT(ic), MSB16, SPEC_USIGN(getSpec(operandType(IC_RESULT(ic)))));
- }
-}
-
-/*-----------------------------------------------------------------*/
-/* genMinus - generates code for subtraction */
-/*-----------------------------------------------------------------*/
-static void genMinus (iCode *ic)
-{
- int size, offset = 0;
- unsigned long lit = 0L;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- aopOp (IC_LEFT(ic),ic,FALSE);
- aopOp (IC_RIGHT(ic),ic,FALSE);
- aopOp (IC_RESULT(ic),ic,TRUE);
-
- /* special cases :- */
- /* if both left & right are in bit space */
- if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
- AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
- genMinusBits (ic);
- goto release ;
- }
-
- /* if I can do an decrement instead
- of subtract then GOOD for ME */
- if (genMinusDec (ic) == TRUE)
- goto release;
-
- size = getDataSize(IC_RESULT(ic));
-
- if(AOP(IC_RIGHT(ic))->type == AOP_LIT) {
- /* Add a literal to something else */
-
- lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
- lit = - (long)lit;
-
- /* add the first byte: */
- emitcode("movlw","0x%x", lit & 0xff);
- emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
-
- offset = 1;
- size--;
-
- while(size--){
-
- emitcode("rlf","_known_zero,w");
- emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
-
- lit >>= 8;
- if(lit & 0xff) {
- emitcode("movlw","0x%x", lit & 0xff);
- emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
-
- }
- offset++;
- }
-
- } else {
-
- emitcode("movf","%s", aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
- emitcode("subwf","%s,f", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
-
- offset = 1;
- size--;
-
- while(size--){
- emitcode("movf","%s,w", aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- emitSKPNC;
- emitcode("incfsz","%s,w",aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
- emitcode("subwf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
-
- }
-
- }
-
-
- // adjustArithmeticResult(ic);
-
-release:
- freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
-}
-
-
-/*-----------------------------------------------------------------*/
-/* genMultbits :- multiplication of bits */
-/*-----------------------------------------------------------------*/
-static void genMultbits (operand *left,
- operand *right,
- operand *result)
-{
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- emitcode("anl","c,%s",AOP(right)->aopu.aop_dir);
- outBitC(result);
-}
-
-
-/*-----------------------------------------------------------------*/
-/* genMultOneByte : 8 bit multiplication & division */
-/*-----------------------------------------------------------------*/
-static void genMultOneByte (operand *left,
- operand *right,
- operand *result)
-{
- sym_link *opetype = operandType(result);
- char *l ;
- symbol *lbl ;
- int size,offset;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* (if two literals, the value is computed before) */
- /* if one literal, literal on the right */
- if (AOP_TYPE(left) == AOP_LIT){
- operand *t = right;
- right = left;
- left = t;
- }
-
- size = AOP_SIZE(result);
- /* signed or unsigned */
- emitcode("mov","b,%s", aopGet(AOP(right),0,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("mul","ab");
- /* if result size = 1, mul signed = mul unsigned */
- aopPut(AOP(result),"a",0);
- if (size > 1){
- if (SPEC_USIGN(opetype)){
- aopPut(AOP(result),"b",1);
- if (size > 2)
- /* for filling the MSBs */
- emitcode("clr","a");
- }
- else{
- emitcode("mov","a,b");
-
- /* adjust the MSB if left or right neg */
-
- /* if one literal */
- if (AOP_TYPE(right) == AOP_LIT){
- /* AND literal negative */
- if((int) floatFromVal (AOP(right)->aopu.aop_lit) < 0){
- /* adjust MSB (c==0 after mul) */
- emitcode("subb","a,%s", aopGet(AOP(left),0,FALSE,FALSE));
- }
- }
- else{
- lbl = newiTempLabel(NULL);
- emitcode("xch","a,%s",aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("cjne","a,#0x80,%05d_DS_", (lbl->key+100));
- emitcode("","%05d_DS_:",(lbl->key+100));
- emitcode("xch","a,%s",aopGet(AOP(right),0,FALSE,FALSE));
- lbl = newiTempLabel(NULL);
- emitcode("jc","%05d_DS_",(lbl->key+100));
- emitcode("subb","a,%s", aopGet(AOP(left),0,FALSE,FALSE));
- emitcode("","%05d_DS_:",(lbl->key+100));
- }
-
- lbl = newiTempLabel(NULL);
- emitcode("xch","a,%s",aopGet(AOP(left),0,FALSE,FALSE));
- emitcode("cjne","a,#0x80,%05d_DS_", (lbl->key+100));
- emitcode("","%05d_DS_:",(lbl->key+100));
- emitcode("xch","a,%s",aopGet(AOP(left),0,FALSE,FALSE));
- lbl = newiTempLabel(NULL);
- emitcode("jc","%05d_DS_",(lbl->key+100));
- emitcode("subb","a,%s", aopGet(AOP(right),0,FALSE,FALSE));
- emitcode("","%05d_DS_:",(lbl->key+100));
-
- aopPut(AOP(result),"a",1);
- if(size > 2){
- /* get the sign */
- emitcode("rlc","a");
- emitcode("subb","a,acc");
- }
- }
- size -= 2;
- offset = 2;
- if (size > 0)
- while (size--)
- aopPut(AOP(result),"a",offset++);
- }
-}
-
-/*-----------------------------------------------------------------*/
-/* 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);
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* assign the amsops */
- aopOp (left,ic,FALSE);
- aopOp (right,ic,FALSE);
- aopOp (result,ic,TRUE);
-
- /* special cases first */
- /* both are bits */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right)== AOP_CRY) {
- genMultbits(left,right,result);
- goto release ;
- }
-
- /* if both are of size == 1 */
- if (AOP_SIZE(left) == 1 &&
- AOP_SIZE(right) == 1 ) {
- genMultOneByte(left,right,result);
- goto release ;
- }
-
- /* should have been converted to function call */
- assert(1) ;
-
-release :
- freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
-}
-
-/*-----------------------------------------------------------------*/
-/* genDivbits :- division of bits */
-/*-----------------------------------------------------------------*/
-static void genDivbits (operand *left,
- operand *right,
- operand *result)
-{
-
- char *l;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* the result must be bit */
- emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE);
-
- MOVA(l);
-
- emitcode("div","ab");
- emitcode("rrc","a");
- aopPut(AOP(result),"c",0);
-}
-
-/*-----------------------------------------------------------------*/
-/* genDivOneByte : 8 bit division */
-/*-----------------------------------------------------------------*/
-static void genDivOneByte (operand *left,
- operand *right,
- operand *result)
-{
- sym_link *opetype = operandType(result);
- char *l ;
- symbol *lbl ;
- int size,offset;
-
- DEBUGemitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- size = AOP_SIZE(result) - 1;
- offset = 1;
- /* signed or unsigned */
- if (SPEC_USIGN(opetype)) {
- /* unsigned is easy */
- emitcode("mov","b,%s", aopGet(AOP(right),0,FALSE,FALSE));
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("div","ab");
- aopPut(AOP(result),"a",0);
- while (size--)
- aopPut(AOP(result),zero,offset++);
- return ;
- }
-
- /* signed is a little bit more difficult */
-
- /* save the signs of the operands */
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- emitcode("xrl","a,%s",aopGet(AOP(right),0,FALSE,TRUE));
- emitcode("push","acc"); /* save it on the stack */
-
- /* now sign adjust for both left & right */
- l = aopGet(AOP(right),0,FALSE,FALSE);
- MOVA(l);
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d_DS_",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d_DS_:",(lbl->key+100));
- emitcode("mov","b,a");
-
- /* sign adjust left side */
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
-
- lbl = newiTempLabel(NULL);
- emitcode("jnb","acc.7,%05d_DS_",(lbl->key+100));
- emitcode("cpl","a");
- emitcode("inc","a");
- emitcode("","%05d_DS_:",(lbl->key+100));