-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathas6-8080.c
220 lines (214 loc) · 5.92 KB
/
as6-8080.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
* 8080 and 8085
* Basic symbol tables.
* Contain all of the instructions
* and register names.
*/
#include "as.h"
/*
* This array of symbol nodes
* make up the basic symbol table.
* The "syminit" routine links these
* nodes into the builtin symbol hash
* table at start-up time.
*/
SYM sym[] = {
{ 0, "b", TBR, B },
{ 0, "c", TBR, C },
{ 0, "d", TBR, D },
{ 0, "e", TBR, E },
{ 0, "h", TBR, H },
{ 0, "l", TBR, L },
{ 0, "a", TBR, A },
{ 0, "m", TBR, M },
{ 0, "sp", TWR, SP },
{ 0, "psw", TWR, PSW },
{ 0, "defb", TDEFB, XXXX },
{ 0, "defw", TDEFW, XXXX },
{ 0, "defs", TDEFS, XXXX },
{ 0, "defm", TDEFM, XXXX },
{ 0, "org", TORG, XXXX },
{ 0, "equ", TEQU, XXXX },
{ 0, "export", TEXPORT, XXXX },
{ 0, ".byte", TDEFB, XXXX },
{ 0, ".word", TDEFW, XXXX },
{ 0, ".blkb", TDEFS, XXXX },
{ 0, ".ds", TDEFS, XXXX },
{ 0, ".ascii", TDEFM, XXXX },
{ 0, ".org", TORG, XXXX },
{ 0, ".equ", TEQU, XXXX },
{ 0, ".export", TEXPORT, XXXX },
{ 0, "cond", TCOND, XXXX },
{ 0, "endc", TENDC, XXXX },
{ 0, "code", TSEGMENT, CODE },
{ 0, "data", TSEGMENT, DATA },
{ 0, "bss", TSEGMENT, BSS },
{ 0, "discard", TSEGMENT, DISCARD },
{ 0, "common", TSEGMENT, COMMON },
{ 0, "literal", TSEGMENT, LITERAL },
{ 0, "commondata", TSEGMENT, COMMONDATA },
{ 0, "buffers", TSEGMENT, BUFFERS },
{ 0, ".code", TSEGMENT, CODE },
{ 0, ".data", TSEGMENT, DATA },
{ 0, ".bss", TSEGMENT, BSS },
{ 0, ".discard", TSEGMENT, DISCARD },
{ 0, ".common", TSEGMENT, COMMON },
{ 0, ".literal", TSEGMENT, LITERAL },
{ 0, ".commondata", TSEGMENT, COMMONDATA },
{ 0, ".buffers", TSEGMENT, BUFFERS },
{ 0, ".setcpu", TSETCPU, XXXX },
{ 0, ".bptr", TBPTR, XXXX },
/* First quadrant, various miscellaneous groupings with 3 bit
register encoding */
{ 0, "nop", TIMPL, 0x0000 },
{ 0, "lxi", TREG16_I16, 0x0001 },
{ 0, "stax", TREG16BD, 0x0002 },
{ 0, "inx", TREG16, 0x0003 },
{ 0, "inr", TREG8H, 0x0004 },
{ 0, "dcr", TREG8H, 0x0005 },
{ 0, "mvi", TREG8_I8, 0x0006 },
{ 0, "rlc", TIMPL, 0x0007 },
{ 0, "dsub", TIMPL85, 0x0008 },
{ 0, "dad", TREG16, 0x0009 },
{ 0, "ldax", TREG16BD, 0x000A },
{ 0, "dcx", TREG16, 0x000B },
{ 0, "rrc", TIMPL, 0x000F },
{ 0, "arhl", TIMPL85, 0x0010 },
{ 0, "ral", TIMPL, 0x0017 },
{ 0, "rdel", TIMPL85, 0x0018 },
{ 0, "rar", TIMPL, 0x001F },
{ 0, "rim", TIMPL85, 0x0020 },
{ 0, "shld", TI16, 0x0022 },
{ 0, "daa", TIMPL, 0x0027 },
{ 0, "ldhi", TI8_85, 0x0028 },
{ 0, "lhld", TI16, 0x002A },
{ 0, "cma", TIMPL, 0x002F },
{ 0, "sim", TIMPL85, 0x0030 },
{ 0, "sta", TI16, 0x0032 },
{ 0, "stc", TIMPL, 0x0037 },
{ 0, "ldsi", TI8_85, 0x0038 },
{ 0, "lda", TI16, 0x003A },
{ 0, "cmc", TIMPL, 0x003F },
/* Second quadrant, 2 bits 01 and a pair of 3 bit register encodes */
{ 0, "mov", TMOV, 0x0040 },
/* Special case mov m,m is in fact hlt */
{ 0, "hlt", TIMPL, 0x0076 },
/* Third quadrant, 2 bits 10, 3 bits operation, 3 bit register encode */
{ 0, "add", TREG8, 0x0080 },
{ 0, "adc", TREG8, 0x0088 },
{ 0, "sub", TREG8, 0x0090 },
{ 0, "sbb", TREG8, 0x0098 },
{ 0, "ana", TREG8, 0x00A0 },
{ 0, "xra", TREG8, 0x00A8 },
{ 0, "ora", TREG8, 0x00B0 },
{ 0, "cmp", TREG8, 0x00B8 },
/* Fourth quadrant - bit of a mix */
{ 0, "rnz", TIMPL, 0x00C0 },
{ 0, "pop", TREG16_P, 0x00C1 },
{ 0, "jnz", TI16, 0x00C2 },
{ 0, "jmp", TI16, 0x00C3 },
{ 0, "cnz", TI16, 0x00C4 },
{ 0, "push", TREG16_P, 0x00C5 },
{ 0, "adi", TI8, 0x00C6 },
{ 0, "rst", TRST, 0x00C7 },
{ 0, "rz", TIMPL, 0x00C8 },
{ 0, "ret", TIMPL, 0x00C9 },
{ 0, "jz", TI16, 0x00CA },
{ 0, "rstv", TIMPL85, 0x00CB },
{ 0, "cz", TI16, 0x00CC },
{ 0, "call", TI16, 0x00CD },
{ 0, "aci", TI8, 0x00CE },
{ 0, "rnc", TIMPL, 0x00D0 },
{ 0, "jnc", TI16, 0x00D2 },
{ 0, "out", TI8, 0x00D3 },
{ 0, "cnc", TI16, 0x00D4 },
{ 0, "sui", TI8, 0x00D6 },
{ 0, "rc", TIMPL, 0x00D8 },
{ 0, "shlx", TIMPL85, 0x00D9 },
{ 0, "jc", TI16, 0x00DA },
{ 0, "in", TI8, 0x00DB },
{ 0, "cc", TI16, 0x00DC },
{ 0, "jnk", TI16_85, 0x00DD },
{ 0, "sbi", TI8, 0x00DE },
{ 0, "rpo", TIMPL, 0x00E0 },
{ 0, "jpo", TI16, 0x00E2 },
{ 0, "xthl", TIMPL, 0x00E3 },
{ 0, "cpo", TI16, 0x00E4 },
{ 0, "ani", TI8, 0x00E6 },
{ 0, "rpe", TIMPL, 0x00E8 },
{ 0, "pchl", TIMPL, 0x00E9 },
{ 0, "jpe", TI16, 0x00EA },
{ 0, "xchg", TIMPL, 0x00EB },
{ 0, "cpe", TI16, 0x00EC },
{ 0, "lhlx", TIMPL85, 0x00ED },
{ 0, "xri", TI8, 0x00EE },
{ 0, "rp", TIMPL, 0x00F0 },
{ 0, "jp", TI16, 0x00F2 },
{ 0, "di", TIMPL, 0x00F3 },
{ 0, "cp", TI16, 0x00F4 },
{ 0, "ori", TI8, 0x00F6 },
{ 0, "rm", TIMPL, 0x00F8 },
{ 0, "sphl", TIMPL, 0x00F9 },
{ 0, "jm", TI16, 0x00FA },
{ 0, "ei", TIMPL, 0x00FB },
{ 0, "cm", TI16, 0x00FC },
{ 0, "jk", TI16_85, 0x00FD },
{ 0, "cpi", TI8, 0x00FE },
};
/*
* Set up the symbol table.
* Sweep through the initializations
* of the "phash", and link them into the
* buckets. Because it is here, a
* "sizeof" works.
*/
void syminit(void)
{
SYM *sp;
int hash;
sp = &sym[0];
while (sp < &sym[sizeof(sym)/sizeof(SYM)]) {
hash = symhash(sp->s_id);
sp->s_fp = phash[hash];
phash[hash] = sp;
++sp;
}
}
char *etext[] = {
"unexpected character",
"phase error",
"multiple definitions",
"syntax error",
"must be absolute",
"missing delimiter",
"invalid constant",
"",
"condition required",
"invalid register for operation",
"address required",
"invalid id",
"",
"divide by 0",
"constant out of range",
"data in BSS",
"segment overflow",
"",
"8085 instruction",
"segment conflict",
"unknown symbol"
};
/*
* Make sure that the
* mode and register fields of
* the type of the "ADDR" pointed to
* by "ap" can participate in an addition
* or a subtraction.
*/
void isokaors(ADDR *ap, int paren)
{
int mode;
mode = ap->a_type&TMMODE;
if (mode == TUSER)
return;
aerr(ADDR_REQUIRED);
}