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"
63 /*-----------------------------------------------------------------*/
64 /* pic16_genNot - generate code for ! operation */
65 /*-----------------------------------------------------------------*/
66 void pic16_genNot (iCode *ic)
71 * result[AOP_CRY,AOP_REG] = ! left[AOP_CRY, AOP_REG]
74 DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
75 /* assign asmOps to operand & result */
76 pic16_aopOp (IC_LEFT(ic),ic,FALSE);
77 pic16_aopOp (IC_RESULT(ic),ic,TRUE);
78 DEBUGpic16_pic16_AopType(__LINE__,IC_LEFT(ic),NULL,IC_RESULT(ic));
80 /* if in bit space then a special case */
81 if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY) {
82 if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) {
83 pic16_emitpcode(POC_MOVLW,pic16_popGet(AOP(IC_LEFT(ic)),0));
84 pic16_emitpcode(POC_XORWF,pic16_popGet(AOP(IC_RESULT(ic)),0));
86 pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(IC_RESULT(ic)),0));
87 pic16_emitpcode(POC_BTFSS,pic16_popGet(AOP(IC_LEFT(ic)),0));
88 pic16_emitpcode(POC_INCF,pic16_popGet(AOP(IC_RESULT(ic)),0));
93 size = AOP_SIZE(IC_LEFT(ic));
95 pic16_emitpcode(POC_COMFW,pic16_popGet(AOP(IC_LEFT(ic)),0));
96 pic16_emitpcode(POC_ANDLW,pic16_popGetLit(1));
97 pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(IC_RESULT(ic)),0));
102 /* release the aops */
103 pic16_freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
104 pic16_freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
107 #endif /* defined(GEN_Not) */
112 /*-----------------------------------------------------------------*/
113 /* pic16_genCpl - generate code for complement */
114 /*-----------------------------------------------------------------*/
115 void pic16_genCpl (iCode *ic)
121 * result[CRY,REG] = ~left[CRY,REG]
125 DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
126 /* assign asmOps to operand & result */
127 pic16_aopOp (IC_LEFT(ic),ic,FALSE);
128 pic16_aopOp (IC_RESULT(ic),ic,TRUE);
129 DEBUGpic16_pic16_AopType(__LINE__,IC_LEFT(ic),NULL,IC_RESULT(ic));
131 /* if both are in bit space then
133 if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
134 AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) {
137 pic16_emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir);
138 pic16_emitcode("cpl","c");
139 pic16_emitcode("mov","%s,c",IC_RESULT(ic)->aop->aopu.aop_dir);
143 size = AOP_SIZE(IC_RESULT(ic));
146 if (pic16_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
147 pic16_emitpcode(POC_COMF, pic16_popGet(AOP(IC_LEFT(ic)), offset));
149 pic16_emitpcode(POC_COMFW, pic16_popGet(AOP(IC_LEFT(ic)),offset));
150 pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(IC_RESULT(ic)),offset));
156 /* release the aops */
157 pic16_freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
158 pic16_freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
160 #endif /* defined(GEN_Cpl) */