struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / sdas / aspdk / pdkadr.c
blob438b4c3804f92ad2e87ae612c67a618ab1605347
1 /* pdkadr.c */
3 /*
4 * Copyright (C) 1998-2009 Alan R. Baldwin
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Alan R. Baldwin
21 * 721 Berkeley St.
22 * Kent, Ohio 44240
24 * This Assember Ported by
25 * John L. Hartman (JLH)
26 * jhartman at compuserve dot com
27 * noice at noicedebugger dot com
31 #include "asxxxx.h"
32 #include "pdk.h"
35 /* Classify argument as to address mode */
36 int
37 addr(struct expr *esp, bool ioAdr)
39 int c = getnb(), c1;
41 switch (c) {
42 case '#':
43 /* Immediate mode */
44 expr(esp, 0);
45 esp->e_mode = S_K;
46 break;
48 case 'a':
49 /* Accumulator */
50 esp->e_mode = S_A;
51 break;
53 case 's':
54 if ((c1 = getnb()) == 'p') {
55 /* Stack (SP) */
56 esp->e_mode = S_IO;
57 esp->e_addr = 2;
58 break;
60 unget(c1);
61 goto fallback;
63 case 'f':
64 /* ACC flag */
65 esp->e_mode = S_IO;
66 esp->e_addr = 0;
67 break;
69 default:
70 fallback:
71 unget(c);
73 expr(esp, 0);
74 /* Memory spaces */
75 if (ioAdr)
76 esp->e_mode = S_IO;
77 else
78 esp->e_mode = S_M;
81 if(pass == 2 && esp->e_mode == S_IO && !ioAdr)
83 warnBanner();
84 fprintf(stderr,
85 "Forced IO address space for instruction without .io\n");
88 return (esp->e_mode);
91 int
92 pdkbit(struct expr *esp)
94 int c = getnb(), c1;
96 switch (c) {
97 case '#':
98 /* Bit number */
99 expr(esp, 0);
100 esp->e_mode = S_K;
101 break;
103 case 'a':
104 if ((c1 = getnb()) == 'c') {
105 /* AC bit of ACC flag */
106 esp->e_mode = S_K;
107 esp->e_addr = 2;
108 break;
110 unget(c1);
111 goto fallback;
113 case 'o':
114 if ((c1 = getnb()) == 'v') {
115 /* OV bit of ACC flag */
116 esp->e_mode = S_K;
117 esp->e_addr = 3;
118 break;
120 unget(c1);
121 goto fallback;
123 case 'c':
124 /* C bit of ACC flag */
125 esp->e_mode = S_K;
126 esp->e_addr = 1;
127 break;
129 case 'z':
130 /* Z bit of ACC flag */
131 esp->e_mode = S_K;
132 esp->e_addr = 0;
133 break;
135 case 'f':
136 /* ACC status flag */
137 esp->e_mode = S_IO;
138 esp->e_addr = -2;
139 break;
141 default:
142 fallback:
143 unget(c);
145 /* Error */
146 esp->e_mode = 0;
147 esp->e_addr = 0;
150 return (esp->e_mode);