1 /*-------------------------------------------------------------------------
2 genutils.c - source file for code generation for pic16
3 code generation utility functions
5 Created by Vangelis Rokas (vrokas@otenet.gr) [Nov-2003]
9 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998)
10 and - Jean-Louis VERN.jlvern@writeme.com (1999)
11 Bug Fixes - Wojciech Stryjewski wstryj1@tiger.lsu.edu (1999 v2.1.9a)
12 PIC port - Scott Dattalo scott@dattalo.com (2000)
13 PIC16 port - Martin Dubuc m.dubuc@rogers.com (2002)
15 This program is free software; you can redistribute it and/or modify it
16 under the terms of the GNU General Public License as published by the
17 Free Software Foundation; either version 2, or (at your option) any
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 In other words, you are welcome to use, share and improve this program.
30 You are forbidden to forbid anyone else to use, share and improve
31 what you give them. Help stamp out software-hoarding!
34 000123 mlh Moved aopLiteral to SDCCglue.c to help the split
35 Made everything static
36 -------------------------------------------------------------------------*/
38 /**********************************************************
39 * Here is a list with completed genXXXXX functions
50 #include "SDCCglobl.h"
54 #include "SDCCpeeph.h"
62 #define pic16_emitcode DEBUGpic16_emitcode
66 /*-----------------------------------------------------------------*/
67 /* pic16_genNot - generate code for ! operation */
68 /*-----------------------------------------------------------------*/
69 void pic16_genNot (iCode *ic)
74 * result[AOP_CRY,AOP_REG] = ! left[AOP_CRY, AOP_REG]
77 DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
78 /* assign asmOps to operand & result */
79 pic16_aopOp (IC_LEFT(ic),ic,FALSE);
80 pic16_aopOp (IC_RESULT(ic),ic,TRUE);
81 DEBUGpic16_pic16_AopType(__LINE__,IC_LEFT(ic),NULL,IC_RESULT(ic));
83 /* if in bit space then a special case */
84 if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY) {
85 if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) {
86 pic16_emitpcode(POC_MOVLW,pic16_popGet(AOP(IC_LEFT(ic)),0));
87 pic16_emitpcode(POC_XORWF,pic16_popGet(AOP(IC_RESULT(ic)),0));
89 pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(IC_RESULT(ic)),0));
90 pic16_emitpcode(POC_BTFSS,pic16_popGet(AOP(IC_LEFT(ic)),0));
91 pic16_emitpcode(POC_INCF,pic16_popGet(AOP(IC_RESULT(ic)),0));
96 size = AOP_SIZE(IC_LEFT(ic));
98 pic16_emitpcode(POC_COMFW,pic16_popGet(AOP(IC_LEFT(ic)),0));
99 pic16_emitpcode(POC_ANDLW,pic16_popGetLit(1));
100 pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(IC_RESULT(ic)),0));
105 /* release the aops */
106 pic16_freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
107 pic16_freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
110 #endif /* defined(GEN_Not) */
115 /*-----------------------------------------------------------------*/
116 /* pic16_genCpl - generate code for complement */
117 /*-----------------------------------------------------------------*/
118 void pic16_genCpl (iCode *ic)
124 * result[CRY,REG] = ~left[CRY,REG]
128 DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
129 /* assign asmOps to operand & result */
130 pic16_aopOp (IC_LEFT(ic),ic,FALSE);
131 pic16_aopOp (IC_RESULT(ic),ic,TRUE);
132 DEBUGpic16_pic16_AopType(__LINE__,IC_LEFT(ic),NULL,IC_RESULT(ic));
134 /* if both are in bit space then
136 if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
137 AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) {
140 pic16_emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir);
141 pic16_emitcode("cpl","c");
142 pic16_emitcode("mov","%s,c",IC_RESULT(ic)->aop->aopu.aop_dir);
146 size = AOP_SIZE(IC_RESULT(ic));
149 if (pic16_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
150 pic16_emitpcode(POC_COMF, pic16_popGet(AOP(IC_LEFT(ic)), offset));
152 pic16_emitpcode(POC_COMFW, pic16_popGet(AOP(IC_LEFT(ic)),offset));
153 pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(IC_RESULT(ic)),offset));
159 /* release the aops */
160 pic16_freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
161 pic16_freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
163 #endif /* defined(GEN_Cpl) */