1 /*-------------------------------------------------------------------------
2 genarith.c - source file for code generation - arithmetic
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998)
5 and - Jean-Louis VERN.jlvern@writeme.com (1999)
6 Bug Fixes - Wojciech Stryjewski wstryj1@tiger.lsu.edu (1999 v2.1.9a)
7 PIC port - Scott Dattalo scott@dattalo.com (2000)
9 This program is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the
11 Free Software Foundation; either version 2, or (at your option) any
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 In other words, you are welcome to use, share and improve this program.
24 You are forbidden to forbid anyone else to use, share and improve
25 what you give them. Help stamp out software-hoarding!
28 000123 mlh Moved aopLiteral to SDCCglue.c to help the split
29 Made everything static
30 -------------------------------------------------------------------------*/
36 #include "SDCCglobl.h"
40 #define __FUNCTION__ __FILE__
43 #ifdef HAVE_SYS_ISA_DEFS_H
44 #include <sys/isa_defs.h>
46 #ifdef HAVE_MACHINE_ENDIAN_H
47 #include <machine/endian.h>
52 #if !defined(__BORLANDC__) && !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__CYGWIN__)
53 #warning "Cannot determine ENDIANESS of this machine assuming LITTLE_ENDIAN"
54 #warning "If you running sdcc on an INTEL 80x86 Platform you are okay"
61 #include "SDCCpeeph.h"
66 /*-----------------------------------------------------------------*/
67 /* genPlusIncr :- does addition with increment if possible */
68 /*-----------------------------------------------------------------*/
69 bool genPlusIncr (iCode *ic)
72 unsigned int size = pic14_getDataSize(IC_RESULT(ic));
74 DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
75 DEBUGpic14_emitcode ("; ","result %d, left %d, right %d",
76 AOP_TYPE(IC_RESULT(ic)),
77 AOP_TYPE(IC_LEFT(ic)),
78 AOP_TYPE(IC_RIGHT(ic)));
80 /* will try to generate an increment */
81 /* if the right side is not a literal
83 if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
86 DEBUGpic14_emitcode ("; ","%s %d",__FUNCTION__,__LINE__);
87 /* if the literal value of the right hand side
88 is greater than 1 then it is faster to add */
89 if ((icount = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit)) > 2)
92 /* if increment 16 bits in register */
93 if (pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) &&
98 emitpcode(POC_INCF, popGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
99 //pic14_emitcode("incf","%s,f",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
103 emitpcode(POC_INCF, popGet(AOP(IC_RESULT(ic)),offset++,FALSE,FALSE));
104 //pic14_emitcode(" incf","%s,f",aopGet(AOP(IC_RESULT(ic)),offset++,FALSE,FALSE));
110 DEBUGpic14_emitcode ("; ","%s %d",__FUNCTION__,__LINE__);
111 /* if left is in accumulator - probably a bit operation*/
112 if( strcmp(aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE),"a") &&
113 (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) ) {
115 emitpcode(POC_BCF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
116 pic14_emitcode("bcf","(%s >> 3), (%s & 7)",
117 AOP(IC_RESULT(ic))->aopu.aop_dir,
118 AOP(IC_RESULT(ic))->aopu.aop_dir);
120 emitpcode(POC_XORLW,popGetLit(1));
121 //pic14_emitcode("xorlw","1");
123 emitpcode(POC_ANDLW,popGetLit(1));
124 //pic14_emitcode("andlw","1");
127 emitpcode(POC_BSF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
128 pic14_emitcode("bsf","(%s >> 3), (%s & 7)",
129 AOP(IC_RESULT(ic))->aopu.aop_dir,
130 AOP(IC_RESULT(ic))->aopu.aop_dir);
137 /* if the sizes are greater than 1 then we cannot */
138 if (AOP_SIZE(IC_RESULT(ic)) > 1 ||
139 AOP_SIZE(IC_LEFT(ic)) > 1 )
142 /* If we are incrementing the same register by two: */
144 if (pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
147 emitpcode(POC_INCF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
148 //pic14_emitcode("incf","%s,f",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
153 DEBUGpic14_emitcode ("; ","couldn't increment result-%s left-%s",
154 aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),
155 aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
159 /*-----------------------------------------------------------------*/
160 /* pic14_outBitAcc - output a bit in acc */
161 /*-----------------------------------------------------------------*/
162 void pic14_outBitAcc(operand *result)
164 symbol *tlbl = newiTempLabel(NULL);
165 /* if the result is a bit */
166 DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
168 if (AOP_TYPE(result) == AOP_CRY){
169 aopPut(AOP(result),"a",0);
172 pic14_emitcode("jz","%05d_DS_",tlbl->key+100);
173 pic14_emitcode("mov","a,#01");
174 pic14_emitcode("","%05d_DS_:",tlbl->key+100);
175 pic14_outAcc(result);
179 /*-----------------------------------------------------------------*/
180 /* genPlusBits - generates code for addition of two bits */
181 /*-----------------------------------------------------------------*/
182 void genPlusBits (iCode *ic)
185 DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
187 The following block of code will add two bits.
188 Note that it'll even work if the destination is
189 the carry (C in the status register).
190 It won't work if the 'Z' bit is a source or destination.
193 /* If the result is stored in the accumulator (w) */
194 //if(strcmp(aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),"a") == 0 ) {
195 if(AOP_TYPE(IC_RESULT(ic)) != AOP_ACC) {
196 //emitpcode( ( ((int) operandLitValue(right)) ? POC_BSF : POC_BCF),
197 // popGet(AOP(result),0,FALSE,FALSE));
199 emitpcode(POC_MOVLW, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
200 emitpcode(POC_BCF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
201 emitpcode(POC_BTFSC, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
202 emitpcode(POC_XORWF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
203 emitpcode(POC_BTFSC, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
204 emitpcode(POC_XORWF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
206 pic14_emitcode("movlw","(1 << (%s & 7))",
207 AOP(IC_RESULT(ic))->aopu.aop_dir,
208 AOP(IC_RESULT(ic))->aopu.aop_dir);
209 pic14_emitcode("bcf","(%s >> 3), (%s & 7)",
210 AOP(IC_RESULT(ic))->aopu.aop_dir,
211 AOP(IC_RESULT(ic))->aopu.aop_dir);
212 pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
213 AOP(IC_RIGHT(ic))->aopu.aop_dir,
214 AOP(IC_RIGHT(ic))->aopu.aop_dir);
215 pic14_emitcode("xorwf","(%s >>3),f",
216 AOP(IC_RESULT(ic))->aopu.aop_dir);
217 pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
218 AOP(IC_LEFT(ic))->aopu.aop_dir,
219 AOP(IC_LEFT(ic))->aopu.aop_dir);
220 pic14_emitcode("xorwf","(%s>>3),f",
221 AOP(IC_RESULT(ic))->aopu.aop_dir);
224 emitpcode(POC_CLRW, NULL);
225 emitpcode(POC_BTFSC, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
226 emitpcode(POC_XORLW, popGetLit(1));
227 emitpcode(POC_BTFSC, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
228 emitpcode(POC_XORLW, popGetLit(1));
230 pic14_emitcode("clrw","");
231 pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
232 AOP(IC_RIGHT(ic))->aopu.aop_dir,
233 AOP(IC_RIGHT(ic))->aopu.aop_dir);
234 pic14_emitcode("xorlw","1");
235 pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
236 AOP(IC_LEFT(ic))->aopu.aop_dir,
237 AOP(IC_LEFT(ic))->aopu.aop_dir);
238 pic14_emitcode("xorlw","1");
244 /* This is the original version of this code.
246 * This is being kept around for reference,
247 * because I am not entirely sure I got it right...
249 static void adjustArithmeticResult(iCode *ic)
251 if (AOP_SIZE(IC_RESULT(ic)) == 3 &&
252 AOP_SIZE(IC_LEFT(ic)) == 3 &&
253 !pic14_sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))))
254 aopPut(AOP(IC_RESULT(ic)),
255 aopGet(AOP(IC_LEFT(ic)),2,FALSE,FALSE),
258 if (AOP_SIZE(IC_RESULT(ic)) == 3 &&
259 AOP_SIZE(IC_RIGHT(ic)) == 3 &&
260 !pic14_sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic))))
261 aopPut(AOP(IC_RESULT(ic)),
262 aopGet(AOP(IC_RIGHT(ic)),2,FALSE,FALSE),
265 if (AOP_SIZE(IC_RESULT(ic)) == 3 &&
266 AOP_SIZE(IC_LEFT(ic)) < 3 &&
267 AOP_SIZE(IC_RIGHT(ic)) < 3 &&
268 !pic14_sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))) &&
269 !pic14_sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic)))) {
271 sprintf(buffer,"#%d",pointerCode(getSpec(operandType(IC_LEFT(ic)))));
272 aopPut(AOP(IC_RESULT(ic)),buffer,2);
276 /* This is the pure and virtuous version of this code.
277 * I'm pretty certain it's right, but not enough to toss the old
280 static void adjustArithmeticResult(iCode *ic)
282 if (opIsGptr(IC_RESULT(ic)) &&
283 opIsGptr(IC_LEFT(ic)) &&
284 !pic14_sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))))
286 aopPut(AOP(IC_RESULT(ic)),
287 aopGet(AOP(IC_LEFT(ic)), GPTRSIZE - 1,FALSE,FALSE),
291 if (opIsGptr(IC_RESULT(ic)) &&
292 opIsGptr(IC_RIGHT(ic)) &&
293 !pic14_sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic))))
295 aopPut(AOP(IC_RESULT(ic)),
296 aopGet(AOP(IC_RIGHT(ic)),GPTRSIZE - 1,FALSE,FALSE),
300 if (opIsGptr(IC_RESULT(ic)) &&
301 AOP_SIZE(IC_LEFT(ic)) < GPTRSIZE &&
302 AOP_SIZE(IC_RIGHT(ic)) < GPTRSIZE &&
303 !pic14_sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic))) &&
304 !pic14_sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic)))) {
306 sprintf(buffer,"#%d",pointerCode(getSpec(operandType(IC_LEFT(ic)))));
307 aopPut(AOP(IC_RESULT(ic)),buffer,GPTRSIZE - 1);
312 /*-----------------------------------------------------------------*/
313 /* genAddlit - generates code for addition */
314 /*-----------------------------------------------------------------*/
315 static void genAddLit2byte (operand *result, int offr, int lit)
322 emitpcode(POC_INCF, popGet(AOP(result),offr,FALSE,FALSE));
325 emitpcode(POC_DECF, popGet(AOP(result),offr,FALSE,FALSE));
328 emitpcode(POC_MOVLW,popGetLit(lit&0xff));
329 emitpcode(POC_ADDWF,popGet(AOP(result),offr,FALSE,FALSE));
334 static void genAddLit (operand *result,operand *left, int lit)
338 int knowW=0,W=0,needC=0;
340 DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
341 size = pic14_getDataSize(result);
343 same = ((left == result) || (AOP(left) == AOP(result)));
347 /* Handle special cases first */
349 genAddLit2byte (result, 0, lit);
352 int hi = 0xff & (lit >> 8);
359 DEBUGpic14_emitcode ("; hi = 0","%s %d",__FUNCTION__,__LINE__);
364 emitpcode(POC_INCF, popGet(AOP(result),0,FALSE,FALSE));
366 emitpcode(POC_INCF, popGet(AOP(result),MSB16,FALSE,FALSE));
369 emitpcode(POC_DECF, popGet(AOP(result),0,FALSE,FALSE));
370 emitpcode(POC_INCFSZW, popGet(AOP(result),0,FALSE,FALSE));
371 emitpcode(POC_INCF, popGet(AOP(result),MSB16,FALSE,FALSE));
375 emitpcode(POC_MOVLW,popGetLit(lit&0xff));
376 emitpcode(POC_ADDWF,popGet(AOP(result),0,FALSE,FALSE));
378 emitpcode(POC_INCF, popGet(AOP(result),MSB16,FALSE,FALSE));
386 DEBUGpic14_emitcode ("; hi = 1","%s %d",__FUNCTION__,__LINE__);
389 emitpcode(POC_INCF, popGet(AOP(result),MSB16,FALSE,FALSE));
392 emitpcode(POC_INCF, popGet(AOP(result),MSB16,FALSE,FALSE));
393 emitpcode(POC_INCF, popGet(AOP(result),0,FALSE,FALSE));
395 emitpcode(POC_INCF, popGet(AOP(result),MSB16,FALSE,FALSE));
397 case 0xff: /* 0x01ff */
398 emitpcode(POC_DECF, popGet(AOP(result),0,FALSE,FALSE));
399 emitpcode(POC_INCFSZW, popGet(AOP(result),0,FALSE,FALSE));
400 emitpcode(POC_INCF, popGet(AOP(result),MSB16,FALSE,FALSE));
401 emitpcode(POC_INCF, popGet(AOP(result),MSB16,FALSE,FALSE));
406 DEBUGpic14_emitcode ("; hi = ff","%s %d",__FUNCTION__,__LINE__);
410 emitpcode(POC_DECF, popGet(AOP(result),MSB16,FALSE,FALSE));
413 emitpcode(POC_INCFSZ, popGet(AOP(result),0,FALSE,FALSE));
414 emitpcode(POC_DECF, popGet(AOP(result),MSB16,FALSE,FALSE));
416 /* case 0xff: * 0xffff *
417 emitpcode(POC_INCFSZW, popGet(AOP(result),0,FALSE,FALSE));
418 emitpcode(POC_INCF, popGet(AOP(result),MSB16,FALSE,FALSE));
419 emitpcode(POC_DECF, popGet(AOP(result),0,FALSE,FALSE));
423 emitpcode(POC_MOVLW,popGetLit(lo));
424 emitpcode(POC_ADDWF,popGet(AOP(result),0,FALSE,FALSE));
426 emitpcode(POC_DECF, popGet(AOP(result),MSB16,FALSE,FALSE));
433 DEBUGpic14_emitcode ("; hi is generic","%d %s %d",hi,__FUNCTION__,__LINE__);
438 genAddLit2byte (result, MSB16, hi);
441 emitpcode(POC_MOVLW,popGetLit((hi+1)&0xff));
442 emitpcode(POC_INCFSZ, popGet(AOP(result),0,FALSE,FALSE));
443 emitpcode(POC_MOVLW,popGetLit(hi));
444 emitpcode(POC_ADDWF,popGet(AOP(result),MSB16,FALSE,FALSE));
446 /* case 0xff: * 0xHHff *
447 emitpcode(POC_MOVFW, popGet(AOP(result),0,FALSE,FALSE));
448 emitpcode(POC_DECF, popGet(AOP(result),MSB16,FALSE,FALSE));
449 emitpcode(POC_MOVLW,popGetLit(hi));
450 emitpcode(POC_ADDWF,popGet(AOP(result),MSB16,FALSE,FALSE));
452 */ default: /* 0xHHLL */
453 emitpcode(POC_MOVLW,popGetLit(lo));
454 emitpcode(POC_ADDWF, popGet(AOP(result),0,FALSE,FALSE));
455 emitpcode(POC_MOVLW,popGetLit(hi));
457 emitpcode(POC_MOVLW,popGetLit((hi+1) & 0xff));
458 emitpcode(POC_ADDWF,popGet(AOP(result),MSB16,FALSE,FALSE));
466 DEBUGpic14_emitcode ("; left and result aren't same","%s %d",__FUNCTION__,__LINE__);
472 emitpcode(POC_MOVFW, popGet(AOP(left),0,FALSE,FALSE));
473 emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
476 emitpcode(POC_INCFW, popGet(AOP(left),0,FALSE,FALSE));
477 emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
480 emitpcode(POC_DECFW, popGet(AOP(left),0,FALSE,FALSE));
481 emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
484 emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
485 emitpcode(POC_ADDFW, popGet(AOP(left),0,FALSE,FALSE));
486 emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
491 emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
492 emitpcode(POC_ADDFW, popGet(AOP(left),0,FALSE,FALSE));
494 emitpcode(POC_MOVFW, popGet(AOP(left),0,FALSE,FALSE));
496 emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
501 emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
502 emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE));
503 emitpcode(POC_MOVFW, popGet(AOP(left),offset,FALSE,FALSE));
505 emitpcode(POC_INCFSZW,popGet(AOP(left),offset,FALSE,FALSE));
506 emitpcode(POC_ADDWF, popGet(AOP(result),offset,FALSE,FALSE));
508 emitpcode(POC_CLRF, popGet(AOP(result),offset,FALSE,FALSE));
509 emitpcode(POC_RLF, popGet(AOP(result),offset,FALSE,FALSE));
510 emitpcode(POC_MOVFW, popGet(AOP(left),offset,FALSE,FALSE));
511 emitpcode(POC_ADDWF, popGet(AOP(result),offset,FALSE,FALSE));
519 /*-----------------------------------------------------------------*/
520 /* genPlus - generates code for addition */
521 /*-----------------------------------------------------------------*/
522 void genPlus (iCode *ic)
524 int size, offset = 0;
526 /* special cases :- */
527 DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
529 aopOp (IC_LEFT(ic),ic,FALSE);
530 aopOp (IC_RIGHT(ic),ic,FALSE);
531 aopOp (IC_RESULT(ic),ic,TRUE);
533 /* if literal, literal on the right or
534 if left requires ACC or right is already
537 if (AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) {
538 operand *t = IC_RIGHT(ic);
539 IC_RIGHT(ic) = IC_LEFT(ic);
543 /* if both left & right are in bit space */
544 if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
545 AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
550 /* if left in bit space & right literal */
551 if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
552 AOP_TYPE(IC_RIGHT(ic)) == AOP_LIT) {
553 /* if result in bit space */
554 if(AOP_TYPE(IC_RESULT(ic)) == AOP_CRY){
555 if((unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit) != 0L) {
556 emitpcode(POC_MOVLW, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
557 if (!pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) )
558 emitpcode(POC_BTFSC, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
559 emitpcode(POC_XORWF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
562 size = pic14_getDataSize(IC_RESULT(ic));
564 MOVA(aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
565 pic14_emitcode("addc","a,#00 ;%d",__LINE__);
566 aopPut(AOP(IC_RESULT(ic)),"a",offset++);
572 /* if I can do an increment instead
573 of add then GOOD for ME */
574 if (genPlusIncr (ic) == TRUE)
577 size = pic14_getDataSize(IC_RESULT(ic));
579 if(AOP(IC_RIGHT(ic))->type == AOP_LIT) {
580 /* Add a literal to something else */
582 unsigned lit = (unsigned) floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
586 DEBUGpic14_emitcode(";","adding lit to something. size %d",size);
588 genAddLit ( IC_RESULT(ic),IC_LEFT(ic), lit);
592 DEBUGpic14_emitcode(";","size %d",size);
594 switch (lit & 0xff) {
598 if(pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))))
599 emitpcode(POC_INCF, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
602 emitpcode(POC_INCFW, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
603 if(AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
604 emitpcode(POC_MOVWF, popGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
608 if(pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))))
609 emitpcode(POC_DECF, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
612 emitpcode(POC_DECFW, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
613 if(AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
614 emitpcode(POC_MOVWF, popGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
618 if( !know_W || ( (lit&0xff) != l1) ) {
620 emitpcode(POC_MOVLW,popGetLit(lit&0xff));
622 if(pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic)))) {
623 emitpcode(POC_ADDWF, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
626 emitpcode(POC_INCF, popGet(AOP(IC_LEFT(ic)),offset+1,FALSE,FALSE));
631 emitpcode(POC_ADDFW, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
632 emitpcode(POC_MOVWF, popGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
635 emitpcode(POC_INCFW, popGet(AOP(IC_RESULT(ic)),offset+1,FALSE,FALSE));
646 } else if(AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
648 pic14_emitcode(";bitadd","right is bit: %s",aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
649 pic14_emitcode(";bitadd","left is bit: %s",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
650 pic14_emitcode(";bitadd","result is bit: %s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
652 /* here we are adding a bit to a char or int */
654 if (pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
656 emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
657 emitpcode(POC_INCF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
659 pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
660 AOP(IC_RIGHT(ic))->aopu.aop_dir,
661 AOP(IC_RIGHT(ic))->aopu.aop_dir);
662 pic14_emitcode(" incf","%s,f", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
665 if(AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
666 emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
667 emitpcode(POC_XORLW , popGetLit(1));
669 pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
670 AOP(IC_RIGHT(ic))->aopu.aop_dir,
671 AOP(IC_RIGHT(ic))->aopu.aop_dir);
672 pic14_emitcode(" xorlw","1");
674 emitpcode(POC_MOVFW , popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
675 emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
676 emitpcode(POC_INCFW , popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
678 pic14_emitcode("movf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
679 pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
680 AOP(IC_RIGHT(ic))->aopu.aop_dir,
681 AOP(IC_RIGHT(ic))->aopu.aop_dir);
682 pic14_emitcode(" incf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
685 if(AOP_TYPE(IC_RESULT(ic)) != AOP_ACC) {
687 if(AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) {
688 emitpcode(POC_ANDLW , popGetLit(1));
689 emitpcode(POC_BCF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
691 emitpcode(POC_BSF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
693 emitpcode(POC_MOVWF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
694 pic14_emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
702 if (pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
704 emitpcode(POC_BTFSC, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
705 emitpcode(POC_INCF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
707 pic14_emitcode("clrz","");
709 pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
710 AOP(IC_RIGHT(ic))->aopu.aop_dir,
711 AOP(IC_RIGHT(ic))->aopu.aop_dir);
712 pic14_emitcode(" incf","%s,f", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
716 emitpcode(POC_MOVFW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
717 emitpcode(POC_BTFSC, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
718 emitpcode(POC_INCFW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
719 emitpcode(POC_MOVWF, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
722 pic14_emitcode("movf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
723 pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
724 AOP(IC_RIGHT(ic))->aopu.aop_dir,
725 AOP(IC_RIGHT(ic))->aopu.aop_dir);
726 pic14_emitcode(" incf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
727 pic14_emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
733 emitpcode(POC_INCF, popGet(AOP(IC_RESULT(ic)),offset++,FALSE,FALSE));
734 //pic14_emitcode(" incf","%s,f", aopGet(AOP(IC_RIGHT(ic)),offset++,FALSE,FALSE));
741 if(strcmp(aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE),"a") == 0 ) {
742 emitpcode(POC_ADDFW, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
743 emitpcode(POC_MOVWF,popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
746 if ( AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
747 emitpcode(POC_ADDFW, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
748 if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
749 emitpcode(POC_MOVWF,popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
752 emitpcode(POC_MOVFW,popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
754 if (pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) )
755 emitpcode(POC_ADDWF, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
757 if( (AOP_TYPE(IC_LEFT(ic)) == AOP_IMMD) ||
758 (AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ) {
759 emitpcode(POC_ADDLW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
761 emitpcode(POC_ADDFW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
762 if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
763 emitpcode(POC_MOVWF,popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
773 if (!pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
774 emitpcode(POC_MOVFW, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
775 emitpcode(POC_MOVWF, popGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
777 pic14_emitcode("movf","%s,w", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
778 pic14_emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
781 emitpcode(POC_MOVFW, popGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
783 emitpcode(POC_INCFSZW, popGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
784 emitpcode(POC_ADDWF, popGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
787 pic14_emitcode("movf","%s,w", aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
789 pic14_emitcode("incfsz","%s,w",aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
790 pic14_emitcode("addwf","%s,f", aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
798 //adjustArithmeticResult(ic);
801 freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
802 freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
803 freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
806 /*-----------------------------------------------------------------*/
807 /* genMinusDec :- does subtraction with decrement if possible */
808 /*-----------------------------------------------------------------*/
809 bool genMinusDec (iCode *ic)
811 unsigned int icount ;
812 unsigned int size = pic14_getDataSize(IC_RESULT(ic));
814 DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
815 /* will try to generate an increment */
816 /* if the right side is not a literal
818 if ((AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT) ||
819 (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY) ||
820 (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) )
823 DEBUGpic14_emitcode ("; lit val","%d",(unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit));
825 /* if the literal value of the right hand side
826 is greater than 4 then it is not worth it */
827 if ((icount = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit)) > 2)
830 /* if decrement 16 bits in register */
831 if (pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) &&
836 emitpcode(POC_DECF, popGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
837 emitpcode(POC_INCFSZW, popGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
838 emitpcode(POC_INCF, popGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
839 emitpcode(POC_DECF, popGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
841 pic14_emitcode("decf","%s,f",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
842 pic14_emitcode("incfsz","%s,w",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
843 pic14_emitcode(" decf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
846 emitpcode(POC_MOVLW, popGetLit(0xff));
847 emitpcode(POC_ADDWF, popGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
849 emitpcode(POC_ADDWF, popGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
851 emitpcode(POC_ADDWF, popGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE));
853 pic14_emitcode("movlw","0xff");
854 pic14_emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
857 pic14_emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
859 pic14_emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE));
863 emitpcode(POC_ADDWF, popGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE));
865 pic14_emitcode("skpnc","");
867 pic14_emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE));
876 /* if the sizes are greater than 1 then we cannot */
877 if (AOP_SIZE(IC_RESULT(ic)) > 1 ||
878 AOP_SIZE(IC_LEFT(ic)) > 1 )
881 /* we can if the aops of the left & result match or
882 if they are in registers and the registers are the
884 if (pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic)))) {
887 emitpcode(POC_DECF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
889 //pic14_emitcode ("decf","%s,f",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
894 DEBUGpic14_emitcode ("; returning"," result=%s, left=%s",
895 aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),
896 aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
899 pic14_emitcode("decf","%s,w",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
900 pic14_emitcode("movwf","%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
902 emitpcode(POC_DECFW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
903 emitpcode(POC_MOVWF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
911 /*-----------------------------------------------------------------*/
912 /* addSign - complete with sign */
913 /*-----------------------------------------------------------------*/
914 void addSign(operand *result, int offset, int sign)
916 int size = (pic14_getDataSize(result) - offset);
917 DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
920 pic14_emitcode("rlc","a");
921 pic14_emitcode("subb","a,acc");
923 aopPut(AOP(result),"a",offset++);
926 aopPut(AOP(result),"#0",offset++);
930 /*-----------------------------------------------------------------*/
931 /* genMinusBits - generates code for subtraction of two bits */
932 /*-----------------------------------------------------------------*/
933 void genMinusBits (iCode *ic)
935 symbol *lbl = newiTempLabel(NULL);
936 DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
937 if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY){
938 pic14_emitcode("mov","c,%s",AOP(IC_LEFT(ic))->aopu.aop_dir);
939 pic14_emitcode("jnb","%s,%05d_DS_",AOP(IC_RIGHT(ic))->aopu.aop_dir,(lbl->key+100));
940 pic14_emitcode("cpl","c");
941 pic14_emitcode("","%05d_DS_:",(lbl->key+100));
942 pic14_outBitC(IC_RESULT(ic));
945 pic14_emitcode("mov","c,%s",AOP(IC_RIGHT(ic))->aopu.aop_dir);
946 pic14_emitcode("subb","a,acc");
947 pic14_emitcode("jnb","%s,%05d_DS_",AOP(IC_LEFT(ic))->aopu.aop_dir,(lbl->key+100));
948 pic14_emitcode("inc","a");
949 pic14_emitcode("","%05d_DS_:",(lbl->key+100));
950 aopPut(AOP(IC_RESULT(ic)),"a",0);
951 addSign(IC_RESULT(ic), MSB16, SPEC_USIGN(getSpec(operandType(IC_RESULT(ic)))));
955 /*-----------------------------------------------------------------*/
956 /* genMinus - generates code for subtraction */
957 /*-----------------------------------------------------------------*/
958 void genMinus (iCode *ic)
960 int size, offset = 0;
961 unsigned long lit = 0L;
963 DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
964 aopOp (IC_LEFT(ic),ic,FALSE);
965 aopOp (IC_RIGHT(ic),ic,FALSE);
966 aopOp (IC_RESULT(ic),ic,TRUE);
968 if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
969 AOP_TYPE(IC_RIGHT(ic)) == AOP_LIT) {
970 operand *t = IC_RIGHT(ic);
971 IC_RIGHT(ic) = IC_LEFT(ic);
975 /* special cases :- */
976 /* if both left & right are in bit space */
977 if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
978 AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
983 /* if I can do an decrement instead
984 of subtract then GOOD for ME */
985 // if (genMinusDec (ic) == TRUE)
988 size = pic14_getDataSize(IC_RESULT(ic));
990 if(AOP(IC_RIGHT(ic))->type == AOP_LIT) {
991 /* Add a literal to something else */
993 lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
996 genAddLit ( IC_RESULT(ic),IC_LEFT(ic), lit);
999 /* add the first byte: */
1000 pic14_emitcode("movlw","0x%x", lit & 0xff);
1001 pic14_emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
1002 emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
1003 emitpcode(POC_ADDWF, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
1015 if((lit & 0xff) == 0xff) {
1016 emitpcode(POC_MOVLW, popGetLit(0xff));
1018 emitpcode(POC_ADDWF, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
1020 emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
1022 emitpcode(POC_MOVLW, popGetLit((lit+1) & 0xff));
1023 emitpcode(POC_ADDWF, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
1027 /* do the rlf known zero trick here */
1028 emitpcode(POC_MOVLW, popGetLit(1));
1030 emitpcode(POC_ADDWF, popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
1035 } else if(AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
1038 pic14_emitcode(";bitsub","right is bit: %s",aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
1039 pic14_emitcode(";bitsub","left is bit: %s",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
1040 pic14_emitcode(";bitsub","result is bit: %s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1042 /* here we are subtracting a bit from a char or int */
1044 if (pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
1046 emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
1047 emitpcode(POC_DECF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1049 pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
1050 AOP(IC_RIGHT(ic))->aopu.aop_dir,
1051 AOP(IC_RIGHT(ic))->aopu.aop_dir);
1052 pic14_emitcode(" incf","%s,f", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1055 if(AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
1056 emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
1057 emitpcode(POC_XORLW , popGetLit(1));
1058 }else if( (AOP_TYPE(IC_LEFT(ic)) == AOP_IMMD) ||
1059 (AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ) {
1061 lit = (unsigned long)floatFromVal(AOP(IC_LEFT(ic))->aopu.aop_lit);
1063 if(AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) {
1064 if (pic14_sameRegs(AOP(IC_RIGHT(ic)), AOP(IC_RESULT(ic))) ) {
1066 emitpcode(POC_MOVLW , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
1067 emitpcode(POC_XORWF , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
1070 emitpcode(POC_BCF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1072 emitpcode(POC_BTFSS , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
1074 emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
1075 emitpcode(POC_BSF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1079 emitpcode(POC_MOVLW , popGetLit(lit & 0xff));
1080 emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
1081 emitpcode(POC_MOVLW , popGetLit((lit-1) & 0xff));
1082 emitpcode(POC_MOVWF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1087 emitpcode(POC_MOVFW , popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
1088 emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
1089 emitpcode(POC_DECFW , popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
1092 if(AOP_TYPE(IC_RESULT(ic)) != AOP_ACC) {
1094 emitpcode(POC_MOVWF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1097 emitpcode(POC_ANDLW , popGetLit(1));
1099 emitpcode(POC_BCF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1101 emitpcode(POC_BSF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1110 if(strcmp(aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE),"a") == 0 ) {
1111 DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
1112 emitpcode(POC_SUBFW, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
1113 emitpcode(POC_SUBLW, popGetLit(0));
1114 emitpcode(POC_MOVWF,popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1117 if ( AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
1118 emitpcode(POC_SUBFW, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
1119 emitpcode(POC_SUBLW, popGetLit(0));
1120 if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
1121 emitpcode(POC_MOVWF,popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1124 DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
1125 if(AOP_TYPE(IC_RIGHT(ic)) != AOP_ACC)
1126 emitpcode(POC_MOVFW,popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
1128 if (pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) )
1129 emitpcode(POC_SUBWF, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
1131 if( (AOP_TYPE(IC_LEFT(ic)) == AOP_IMMD) ||
1132 (AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ) {
1133 emitpcode(POC_SUBLW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
1135 emitpcode(POC_SUBFW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
1137 if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC) {
1138 if ( AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) {
1139 emitpcode(POC_BCF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1141 emitpcode(POC_BSF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1143 emitpcode(POC_MOVWF,popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1150 emitpcode(POC_MOVFW, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
1152 if (pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
1153 emitpcode(POC_SUBFW, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1155 emitpcode(POC_SUBFW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
1156 emitpcode(POC_MOVWF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1163 if (!pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
1164 emitpcode(POC_MOVFW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
1165 emitpcode(POC_MOVWF, popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
1167 emitpcode(POC_MOVFW, popGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
1169 emitpcode(POC_INCFSZW,popGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
1170 emitpcode(POC_SUBWF, popGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
1178 // adjustArithmeticResult(ic);
1181 freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
1182 freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
1183 freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);