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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
/* asmutl.c -- microsoft 80x86 assembler
**
** microsoft (r) macro assembler
** copyright (c) microsoft corp 1986. all rights reserved
**
** randy nevin
**
** 10/90 - Quick conversion to 32 bit by Jeff Spencer
*/
#include <stdio.h>
#include <string.h>
#include "asm86.h"
#include "asmfcn.h"
#include "asmctype.h"
#include "asmindex.h"
#include "asmmsg.h"
extern char *fname;
extern char hexchar[];
/* put a bunch of registers into the symbol table */
VOID initregs(
struct mreg *makreg
){
register struct mreg *index;
register char *p;
char * savelbufp;
savelbufp = lbufp;
for (index = makreg; *index->nm; index++)
{
lbufp = index->nm;
getatom();
if (symsearch())
/* register already defined */
errorn(E_RAD);
symcreate( M_NOCREF | M_BACKREF | M_DEFINED, REGISTER);
symptr->offset = index->val;
symptr->symu.regsym.regtype = index->rt;
symbolcnt--;
}
lbufp = savelbufp;
}
/*** scanorder - process symbol list in order
*
* scanorder (root, fcn);
*
* Entry root = root of symbol list
* fcn = pointer to function to be executed
* Exit none
* Returns none
* Calls
*/
#if !defined XENIX286 && !defined FLATMODEL
# pragma alloc_text (FA_TEXT, scanorder)
#endif
VOID PASCAL
scanorder (
SYMBOL FARSYM *root,
SHORT (PASCAL *item) (SYMBOL FARSYM *)
){
register SYMBOL FARSYM *p;
for (p = root; p; p = p->next) {
symptr = p;
(*item) (p);
}
}
/*** scanSorted - process symbol sorted order
*
* Entry root = root of symbol list
* fcn = pointer to function to be executed
* Exit none
* Returns none
* Calls
*/
#if !defined XENIX286 && !defined FLATMODEL
# pragma alloc_text (FA_TEXT, scanSorted)
#endif
VOID PASCAL
scanSorted (
SYMBOL FARSYM *root,
SHORT (PASCAL *item) (SYMBOL FARSYM *)
){
register SYMBOL FARSYM *p;
for (p = root; p; p = p->alpha) {
symptr = p;
if (!(M_PASSED & p->attr))
(*item) (p);
}
}
/*** assignemitsylinknum - assign link number
*
* assignlinknum (sym);
*
* Entry *sym = symbol
* Exit
* Returns
* Calls
* Note Turn off BACKREF and PASSED bits in symbol attributes and
* if symbol is segment, group, public or external give it a
* link dictionary number
*/
VOID PASCAL
assignlinknum (
register SYMBOL FARSYM *sym
){
switch (sym->symkind) {
case MACRO: /* make symbol unknown at start of p2 */
case STRUC:
case REC:
sym->attr &= ~M_BACKREF;
return;
case SEGMENT:
sym->symu.segmnt.lnameIndex = lnameIndex++;
goto creatLname;
case CLASS:
sym->symu.ext.extIndex = lnameIndex++;
goto creatLname;
/* group indexs holds lname index temporary */
case GROUP:
sym->symu.grupe.groupIndex = lnameIndex++;
creatLname:
emitlname (sym);
}
if (sym->symkind == REGISTER)
sym->attr &= ~(M_PASSED);
else
sym->attr &= ~(M_PASSED | M_BACKREF);
}
/*** scansegment - output segment names
*
* scansegment (sym);
*
* Entry *sym = segment symbol chain
* Exit
* Returns
* Calls
*/
VOID PASCAL
scansegment (
register SYMBOL FARSYM *sym
){
if (sym->symu.segmnt.align == (char)-1)
/* PARA default */
sym->symu.segmnt.align = 3;
if (sym->symu.segmnt.combine == 7)
/* Default no combine */
sym->symu.segmnt.combine = 0;
sym->symu.segmnt.lastseg = NULL;
/* Output segment def */
emitsegment (sym);
/* Clear Offset( current segment PC ) for pass 2 */
sym->offset = 0;
sym->symu.segmnt.seglen = 0;
}
/*** scangroup - output group names
*
* scangroup (sym);
*
* Entry *sym = group chain
* Exit
* Returns
* Calls
*/
VOID PASCAL
scangroup (
SYMBOL FARSYM *sym
){
if (sym->symkind == GROUP)
emitgroup (sym);
}
/*** scanextern - output external names
*
* scanextern (sym);
*
* Entry *sym = chain of external names
* Exit
* Returns
* Calls
*/
VOID PASCAL
scanextern (
SYMBOL FARSYM *sym
){
if (M_XTERN & sym->attr)
emitextern (sym);
}
/*** scanglobal - output global names
*
* scanglobal (sym);
*
* Entry *sym = chain of external names
* Exit
* Returns
* Calls
*/
VOID PASCAL
scanglobal (
SYMBOL FARSYM *sym
){
if (M_GLOBAL & sym->attr)
emitglobal (sym);
}
/*** dumpname - output module name
*
* dumpname ();
*
* Entry
* Exit
* Returns
* Calls
*/
VOID PASCAL
dumpname ()
{
moduleflag = TRUE;
/* put file name instead of the usual */
emodule(createname(fname));
}
/*** showresults - display final assembly results
*
* showresults (fil, verbose, mbytes);
*
* Entry fil = file to print statistics to
* verbose = TRUE if all statistics to be displayed
* FALSE if only error messages to be displayed
* mbytes = number of free bytes in symbol space
* Exit statistics written to file
* Returns none
* Calls fprintf
*/
VOID PASCAL
showresults (
FILE *fil,
char verbose,
char *pFreeBytes
){
if (verbose) {
fprintf (fil, __NMSG_TEXT(ER_SOU), linessrc, linestot);
fprintf (fil, __NMSG_TEXT(ER_SY2), symbolcnt);
}
fprintf (fil, pFreeBytes);
fprintf (fil, "%7hd%s\n%7hd%s\n",
warnnum, __NMSG_TEXT(ER_EM1),
errornum, __NMSG_TEXT(ER_EM2));
#ifdef BUF_STATS
if (verbose) {
extern long DEBUGtl, DEBUGlb, DEBUGbp, DEBUGbl, DEBUGcs, DEBUGca;
fprintf (fil, "\nTotal lines: %ld\n", DEBUGtl);
fprintf (fil, "Lines buffered: %ld\n", DEBUGlb);
fprintf (fil, "Stored as blank: %ld\n", DEBUGbl);
fprintf (fil, "Bad lbufp: %ld\n", DEBUGbp);
fprintf (fil, "Total Characters: %ld\n", DEBUGca);
fprintf (fil, "Characters buffered: %ld\n", DEBUGcs);
}
#endif
#ifdef EXPR_STATS
if (verbose) {
extern long cExpr, cHardExpr;
fprintf(fil, "\nTotal Expressions(%ld), Simple(%ld): %hd%%\n",
cExpr, cExpr - cHardExpr, (SHORT)((cExpr - cHardExpr)*100 / (cExpr+1)));
}
#endif
}
/*** resetobjidx - reset listindex to correct column
*
* resetobjidx ();
*
* Entry
* Exit
* Returns
* Calls
*/
VOID PASCAL CODESIZE
resetobjidx ()
{
listindex = LSTDATA;
if (!emittext && duplevel)
listindex += 3 + ((duplevel <= 8)? duplevel: 8);
if (highWord(pcoffset)) /* check for 32 bit listing */
listindex += 4;
#ifdef BCBOPT
if (fNotStored)
storelinepb ();
#endif
listline ();
linebuffer[0] = 0;
}
/*** copyascii - copy ASCII into list buffer
*
* copyascii ();
*
* Entry objectascii = data to be copied
* listindex = position for copy
* Exit
* Returns
* Calls
*/
VOID PASCAL CODESIZE
copyascii ()
{
register char *p2;
register char *p1;
if (listindex >= LSTMAX)
resetobjidx ();
if (!fNeedList)
return;
for (p1 = listbuffer + listindex, p2 = objectascii; *p2; )
*p1++ = *p2++;
listindex = p1 - listbuffer;
}
/*** copystring - copy ASCII into list buffer
*
* copystring ();
*
* Entry objectascii = data to be copied
* listindex = position for copy
* Exit
* Returns
* Calls
*/
VOID PASCAL CODESIZE
copystring (
register char *strng
){
register char *p1;
if (!fNeedList || fSkipList)
return;
goto firstTime;
while (*strng) {
*p1++ = *strng++;
if (*strng && ++listindex > LSTMAX + 2) {
resetobjidx ();
firstTime:
listindex = 3;
p1 = listbuffer + 3;
}
}
}
/*** copytext - copy two characters to text line
*
* copytext (chrs)
*
* Entry
* Exit
* Returns
* Calls
*/
VOID PASCAL CODESIZE
copytext (
char *chrs
){
if (listindex > LSTMAX+1)
resetobjidx ();
listbuffer[listindex++] = *chrs++;
listbuffer[listindex++] = *chrs;
}
/*** pcdisplay - display program counter
*
* pcdisplay();
*
* Entry pcoffset = value to display
* Exit hex or octal value of pc interted in list buffer
* Returns none
* Calls copyascii, wordascii
*/
VOID PASCAL CODESIZE
pcdisplay ()
{
listindex = 1;
if (!fNeedList)
return;
offsetAscii (pcoffset);
copyascii ();
listindex = LSTDATA;
if (objectascii[4]) /* was a 32bit number */
listindex += 4;
}
/*** opdisplay - display program counter and opcode
*
* opdisplay(v);
*
* Entry v = opcode to display
* Exit none
* Returns none
* Calls
*/
VOID PASCAL CODESIZE
opdisplay (
UCHAR v
){
if (!fNeedList)
return;
if (listindex == 1)
pcdisplay ();
objectascii[1] = hexchar[v & 0xf];
objectascii[0] = hexchar[v >> 4];
objectascii[2] = 0;
copyascii ();
listindex++;
}
#ifndef M8086OPT
/*** inset - check for value in a set of values
*
* flag = inset (val, set);
*
* Entry val = value to check
* set = array of values to check for
* set[0] = number of entries in set
* Exit none
* Returns TRUE if val is in set
* FALSE if val is not in set
* Calls
*/
char CODESIZE
inset (
register char v,
char *s
){
register USHORT i;
register char *p;
for (i = *s, p = ++s; i; i--)
if (v == *p++)
return (TRUE);
return (FALSE);
}
#endif /* M8086OPT */
/*** outofmem - issue an out of memory error message
*
* outofmem (text);
*
* Entry *text = text to append to message
* Exit doesn't
* Returns none
* Calls endblk, parse
* Note if not end of PROC, parse line as normal. Otherwise,
* terminate block.
*/
VOID PASCAL
outofmem ()
{
closeOpenFiles();
terminate((SHORT)((EX_MEME<<12) | ER_MEM), pFCBCur->fname, errorlineno, NULL );
}
SHORT PASCAL CODESIZE
tokenIS(
char *pLiteral
){
return(_stricmp(naim.pszName, pLiteral) == 0);
}
#ifdef M8086
/*** strnfcpy - copy string to near buffer
*
* strnfcpy (dest, src);
*
* Entry dest = pointer to near buffer
* src = pointer to far source buffer
* Exit source copied to destination
* Returns none
* Calls none
*/
VOID PASCAL
strnfcpy (
register char *dest,
register char FAR *src
){
while(*src)
*dest++ = *src++;
*dest = NULL;
}
/*** strflen - compute length of far buffer
*
* strnflen (s1);
*
* Entry s1 = pointer to far buffer
* Exit none
* Returns number of characters in buffer
* Calls none
*/
USHORT PASCAL
strflen (
register char FAR *s1
){
register USHORT i = 0;
while (*s1++)
i++;
return(i);
}
#endif /* M8086 */
|