-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathASM.ASM
4006 lines (3824 loc) · 58.4 KB
/
ASM.ASM
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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Seattle Computer Products 8086 Assembler version 2.44
; by Tim Paterson
; Runs on the 8086 under MS-DOS
;* * * * * * REVISION HISTORY * * * * * *
;
; 12/29/80 2.01 General release with 86-DOS version 0.34
; 02/22/81 2.10 Increased buffer size from 128 bytes to 1024 bytes
; 03/18/81 2.11 General cleanup and more documentation
; 03/24/81 2.20 Modify ESC handling for full 8087 operation
; 04/01/81 2.21 Fix date in HEX and PRN files; modify buffer handling
; 04/03/81 2.22 Fix 2.21 buffer handling
; 04/13/81 2.23 Re-open source file for listing to allow assembling CON:
; 04/28/81 2.24 Allow nested IFs
; 07/30/81 2.25 Add Intel string mnemonics; clean up a little
; 08/02/81 2.30 Re-write pass 2:
; Always report errors to console
; Exact byte lengths for HEX and PRN files
; 11/08/81 2.40 Add 8087 mnemonics; print full error messages;
; allow expressions with *, /, and ()
; 07/04/82 2.41 Fix Intel's 8087 "reverse-bit" bug; don't copy date
; 08/18/82 2.42 Increase stack from 80 to 256 (Damn! Overflowed again!)
; 01/05/83 2.43 Correct over-zealous optimization in 2.42
; 05/09/83 2.44 Add memory usage report
;
;* * * * * * * * * * * * * * * * * * * * *
SYMWID: EQU 5 ;5 symbols per line in dump
FCB: EQU 5CH
BUFSIZ: EQU 1024 ;Source code buffer
LSTBUFSIZ:EQU BUFSIZ ;List file buffer
HEXBUFSIZ:EQU 70 ;Hex file buffer (26*2 + 5*2 + 3 + EXTRA)
EOL: EQU 13 ;ASCII carriage return
OBJECT: EQU 100H ;DEFAULT "PUT" ADDRESS
;System call function codes
PRINTMES: EQU 9
OPEN: EQU 15
CLOSE: EQU 16
READ: EQU 20
SETDMA: EQU 26
MAKE: EQU 22
BLKWRT: EQU 40
;The following equates define some token values returned by GETSYM
UNDEFID:EQU 0 ;Undefined identifier (including no nearby RET)
CONST: EQU 1 ;Constant (including $)
REG: EQU 2 ;8-bit register
XREG: EQU 3 ;16-bit register (except segment registers)
SREG: EQU 4 ;Segment register
FREG: EQU 6 ;8087 floating point register
;Bits to build 8087 opcode table entries
ONEREG: EQU 40H ;Single ST register OK as operand
NEEDOP: EQU 80H ;Must have an operand
INTEGER:EQU 20H ;For integer operations
REAL: EQU 28H ;For real operations
EXTENDED EQU 10H ;For Long integers or Temporary real
MEMORY: EQU 18H ;For general memory operations
STACKOP:EQU 10H ;Two register arithmetic with pop
ARITH: EQU 8 ;Non-pop arithmetic operations
ORG 100H
PUT 100H
JMPS BEGIN
HEADER: DB 13,10,'Seattle Computer Products 8086 Assembler Version 2.44'
DB 13,10,'Copyright 1979-1983 by Seattle Computer Products, Inc.'
DB 13,10,13,10,'$'
BEGIN:
MOV SP,STACK
MOV DX,HEADER
MOV AH,PRINTMES
INT 33
MOV AL,[FCB+17]
MOV [SYMFLG],AL ;Save symbol table request flag
MOV SI,FCB+9 ;Point to file extension
LODB ;Get source drive letter
CALL CHKDSK ;Valid drive?
OR AL,AL
JZ DEFAULT ;If no extension, use existing drive spec
MOV [FCB],AL
DEFAULT:
LODB ;Get HEX file drive letter
CMP AL,'Z' ;Suppress HEX file?
JZ L0000
CALL CHKDSK
L0000:
MOV [HEXFCB],AL
LODB ;Get PRN file drive letter
MOV AH,0 ;Signal no PRN file
CMP AL,'Z' ;Suppress PRN file?
JZ NOPRN
CMP AL,'Y' ;Print errors only on console?
JZ NOPRN
MOV AH,2
CMP AL,'X' ;PRN file to console?
JZ NOPRN
MOV AH,4
CMP AL,'P' ;PRN file to printer?
JZ NOPRN
CALL CHKDSK
MOV AH,80H
NOPRN:
MOV [LSTFCB],AL
MOV [LSTDEV],AH ;Flag device for list ouput
MOV SI,EXTEND
MOV DI,FCB+9
MOVW
MOVB ;Set extension to ASM
MOVW ;Zero extent field
MOV DX,FCB
MOV AH,OPEN
INT 33
MOV BX,NOFILE
OR AL,AL
JZ $+5
JMP PRERR
MOV DX,HEXFCB
CALL MAKFIL
MOV DX,LSTFCB
CALL MAKFIL
XOR AX,AX
MOV [FCB+12],AX ;Zero CURRENT BLOCK field
MOV [FCB+32],AL ;Zero Next Record field
MOV [FCB+14],BUFSIZ ;Set record size
MOV [BUFPT],SRCBUF ;Initialize buffer pointer
MOV [CODE],START+1 ;POINTER TO NEXT BYTE OF INTERMEDIATE CODE
MOV [IY],START ;POINTER TO CURRENT RELOCATION BYTE
XOR AX,AX
MOV [PC],AX ;DEFAULT PROGRAM COUNTER
MOV [BASE],AX ;POINTER TO ROOT OF ID TREE=NIL
MOV [RETPT],AX ;Pointer to last RET record
MOV [IFFLG],AL ;NOT WITHIN IF/ENDIF
MOV [CHKLAB],AL ;LOOKUP ALL LABELS
DEC AX
MOV [LSTRET],AX ;Location of last RET
MOV AX,[6] ;HL=END OF MEMORY
MOV [HEAP],AX ;BACK END OF SYMBOL TABLE SPACE
MOV [BCOUNT],4 ;CODE BYTES PER RELOCATION BYTE
;Assemble each line of code
LOOP:
CALL NEXTCHR ;Get first character on line
CMP AL,1AH
JZ ENDJ
MOV AL,-1 ;Flag that no tokens have been read yet
MOV [SYM],AL
CALL ASMLIN ;Assemble the line
MOV AL,[SYM]
CMP AL,-1 ;Any tokens found on line?
JNZ L0002
CALL GETSYM ;If no tokens read yet, read first one
L0002:
CMP AL,';'
JZ ENDLN
CMP AL,EOL
JZ ENDLN
MOV AL,14H ;Garbage at end of line error
JP ENDLIN
ENDJ: JMP END
ENDLN:
XOR AL,AL ;Flag no errors on line
ENDLIN:
;AL = error code for line. Stack depth unknown
MOV SP,STACK
CALL NEXLIN
JP LOOP
NEXLIN:
MOV CH,0C0H ;Put end of line marker and error code (AL)
CALL PUTCD
CALL GEN1
MOV AL,[CHR]
GETEOL:
CMP AL,10
JZ RET
CMP AL,1AH
JZ ENDJ
CALL NEXTCHR ;Scan over comments for linefeed
JP GETEOL
ABORT:
MOV BX,NOMEM
PRERR:
MOV DX,BX
MOV AH,PRINTMES
INT 33
INT 32
MAKFIL:
MOV SI,DX
LODB ;Get drive select byte
CMP AL,20H ;If not valid, don't make file
JNC RET
MOV CX,4
MOV DI,SI
MOV SI,FCB+1
REP
MOVW ;Copy source file name
MOV AH,MAKE
INT 33
MOV [DI-9+14],1 ;Set record length to 1 byte
MOV BX,NOSPAC
OR AL,AL ;Success?
JNZ PRERR
RET
CHKDSK:
SUB AL,' ' ;If not present, set zero flag
JZ RET
SUB AL,20H
JZ DSKERR ;Must be in range A-O
CMP AL,'P'-'@'
JC RET
DSKERR:
MOV BX,BADDSK
JP PRERR
ERROR:
MOV AL,CL
JMP ENDLIN
NEXTCHR:
MOV SI,[BUFPT]
CMP SI,SRCBUF
JNZ GETCH
;Buffer empty so refill it
PUSH DX
PUSH AX ;AH must be saved
MOV DX,SI
MOV AH,SETDMA
INT 33
MOV DX,FCB
MOV AH,READ
INT 33
XCHG AX,DX ;Put error code in DL
POP AX ;Restore AH
MOV AL,DL ;Error code back in AL
POP DX
CMP AL,1
MOV AL,1AH ;Possibly signal End of File
JZ NOMOD ;If nothing read
GETCH:
LODB
CMP SI,SRCBUF+BUFSIZ
JNZ NOMOD
MOV SI,SRCBUF
NOMOD:
MOV [BUFPT],SI
MOV [CHR],AL
RET
MROPS:
; Get two operands and check for certain types, according to flag byte
; in CL. OP code in CH. Returns only if immediate operation.
PUSH CX ;Save type flags
CALL GETOP
PUSH DX ;Save first operand
CALL GETOP2
POP BX ;First op in BX, second op in DX
MOV AL,SREG ;Check for a segment register
CMP AL,BH
JZ SEGCHK
CMP AL,DH
JZ SEGCHK
MOV AL,CONST ;Check if the first operand is immediate
MOV CL,26
CMP AL,BH
JZ ERROR ;Error if so
POP CX ;Restore type flags
CMP AL,DH ;If second operand is immediate, then done
JZ RET
MOV AL,UNDEFID ;Check for memory reference
CMP AL,BH
JZ STORE ;Is destination memory?
CMP AL,DH
JZ LOAD ;Is source memory?
TEST CL,1 ;Check if register-to-register operation OK
MOV CL,27
JZ ERROR
MOV AL,DH
CMP AL,BH ;Registers must be of same length
RR:
MOV CL,22
JNZ ERROR
RR1:
AND AL,1 ;Get register length (1=16 bits)
OR AL,CH ;Or in to OP code
CALL PUT ;And write it
POP CX ;Dump return address
MOV AL,BL
ADD AL,AL ;Rotate register number into middle position
ADD AL,AL
ADD AL,AL
OR AL,0C0H ;Set register-to-register mode
OR AL,DL ;Combine with other register number
JMP PUT
SEGCHK:
;Come here if at least one operand is a segment register
POP CX ;Restore flags
TEST CL,8 ;Check if segment register OK
MOV CL,22
JZ ERR1
MOV CX,8E03H ;Segment register move OP code
MOV AL,UNDEFID
CMP AL,DH ;Check if source is memory
JZ LOAD
CMP AL,BH ;Check if destination is memory
JZ STORE
MOV AL,XREG
SUB AL,DH ;Check if source is 16-bit register
JZ RR ;If so, AL must be zero
MOV CH,8CH ;Change direction
XCHG DX,BX ;Flip which operand is first and second
MOV AL,XREG
SUB AL,DH ;Let RR perform finish the test
JP RR
STORE:
TEST CL,004H ;Check if storing is OK
JNZ STERR
XCHG DX,BX ;If so, flip operands
AND CH,0FDH ; and zero direction bit
LOAD:
MOV DH,25
CMP AL,BH ;Check if memory-to-memory
JZ MRERR
MOV AL,BH
CMP AL,REG ;Check if 8-bit operation
JNZ XRG
MOV DH,22
TEST CL,1 ;See if 8-bit operation is OK
JZ MRERR
XRG:
MOV AL,DL
SUB AL,6 ;Check for R/M mode 6 and register 0
OR AL,BL ; meaning direct load/store of accumulator
JNZ NOTAC
TEST CL,8 ;See if direct load/store of accumulator
JZ NOTAC ; means anything in this case
; Process direct load/store of accumulator
MOV AL,CH
AND AL,2 ;Preserve direction bit only
XOR AL,2 ; but flip it
OR AL,0A0H ;Combine with OP code
MOV CH,AL
MOV AL,BH ;Check byte/word operation
AND AL,1
OR AL,CH
POP CX ;Dump return address
JMP PUTADD ;Write the address
NOTAC:
MOV AL,BH
AND AL,1 ;Get byte/word bit
AND AL,CL ;But don't use it in word-only operations
OR AL,CH ;Combine with OP code
CALL PUT
MOV AL,BL
ADD AL,AL ;Rotate to middle position
ADD AL,AL
ADD AL,AL
OR AL,DL ;Combine register field
POP CX ;Dump return address
JMP PUTADD ;Write the address
STERR:
MOV DH,29
MRERR:
MOV CL,DH
ERR1: JMP ERROR
GETOP2:
;Get the second operand: look for a comma and drop into GETOP
MOV AL,[SYM]
CMP AL,','
MOV CL,21
JNZ ERR1
GETOP:
; Get one operand. Operand may be a memory reference in brackets, a register,
; or a constant. If a flag (such as "B" for byte operation) is encountered,
; it is noted and processing continues to find the operand.
;
; On exit, AL (=DH) has the type of operand. Other information depends
; on the actual operand:
;
; AL=DH=0 Memory Reference. DL has the address mode properly prepared in
; the 8086 R/M format (middle bits zero). The constant part of the address
; is in ADDR. If an undefined label needs to be added to this, a pointer to
; its information fields is in ALABEL, otherwise ALABEL is zero.
;
; AL=DH=1 Value. The constant part is in DATA. If an undefined label needs
; to be added to this, a pointer to its information fields is in DLABEL,
; otherwise DLABEL is zero. "$" and "RET" are in this class.
;
; AL=DH=2 8-bit Register. DL has the register number.
;
; AL=DH=3 16-bit Register. DL has the register number.
;
; AL=DH=4 Segment Register. DL has the register number.
CALL GETSYM
GETOP1:
;Enter here if we don't need a GETSYM first
CMP AL,'[' ;Memory reference?
JZ MEM
CMP AL,5 ;Flag ("B", "W", etc.)?
JZ FLG
CMP AL,REG ;8-Bit register?
JZ NREG
CMP AL,XREG ;16-Bit register?
JZ NREG
CMP AL,SREG ;Segment register?
JZ NREG
VAL: ;Must be immediate
XOR AL,AL ;No addressing modes allowed
VAL1:
CALL GETVAL
MOV AX,[CON] ;Defined part
MOV [DATA],AX
MOV AX,[UNDEF] ;Undefined part
MOV [DLABEL],AX
MOV DL,CH
MOV DH,CONST
MOV AL,DH
RET
NREG:
PUSH DX
CALL GETSYM
POP DX
MOV AL,DH
RET
MEM:
CALL GETSYM
MOV AL,1
CALL GETVAL
MOV AL,[SYM]
CMP AL,']'
MOV CL,24
JNZ ERR1
CALL GETSYM
MOV BX,[CON]
MOV [ADDR],BX
MOV BX,[UNDEF]
MOV [ALABEL],BX
MOV DL,CH
MOV DH,UNDEFID
MOV AL,DH
RET
FLG:
CMP DL,[MAXFLG] ;Invalid flag for this operation?
MOV CL,27H
JG ERR1
CALL GETSYM
CMP AL,','
JZ GETOP
JP GETOP1
GETVAL:
; Expression analyzer. On entry, if AL=0 then do not allow base or index
; registers. If AL=1, we are analyzing a memory reference, so allow base
; and index registers, and compute addressing mode when done. The constant
; part of the expression will be found in CON. If an undefined label is to
; be added to this, a pointer to its information fields will be found in
; UNDEF.
MOV AH,AL ;Flag is kept in AH
MOV [UNDEF],0
MOV AL,[SYM]
CALL EXPRESSION
MOV [CON],DX
MOV AL,AH
MOV CH,0 ;Initial mode
TEST AL,10H ;Test INDEX bit
RCL AL ;BASE bit (zero flag not affected)
JZ NOIND ;Jump if not indexed, with BASE bit in carry
CMC
RCL CH ;Rotate in BASE bit
RCL AL ;BP bit
RCL CH
RCL AL ;DI bit
RCL CH ;The low 3 bits now have indexing mode
MODE:
OR CH,080H ;If undefined label, force 16-bit displacement
TEST [UNDEF],-1
JNZ RET
MOV BX,[CON]
MOV AL,BL
CBW ;Extend sign
CMP AX,BX ;Is it a signed 8-bit number?
JNZ RET ;If not, use 16-bit displacement
AND CH,07FH ;Reset 16-bit displacement
OR CH,040H ;Set 8-bit displacement
OR BX,BX
JNZ RET ;Use it if not zero displacement
AND CH,7 ;Specify no displacement
CMP CH,6 ;Check for BP+0 addressing mode
JNZ RET
OR CH,040H ;If BP+0, use 8-bit displacement
RET
NOIND:
MOV CH,6 ;Try direct address mode
JNC RET ;If no base register, that's right
RCL AL ;Check BP bit
JC MODE
INC CH ;If not, must be BX
JP MODE
EXPRESSION:
;Analyze arbitrary expression. Flag byte in AH.
;On exit, AL has type byte: 0=register or undefined label
MOV CH,-1 ;Initial type
MOV DI,DX
XOR DX,DX ;Initial value
CMP AL,'+'
JZ PLSMNS
CMP AL,'-'
JZ PLSMNS
MOV CL,'+'
PUSH DX
PUSH CX
MOV DX,DI
JP OPERATE
PLSMNS:
MOV CL,AL
PUSH DX
PUSH CX
OR AH,4 ;Flag that a sign was found
CALL GETSYM
OPERATE:
CALL TERM
POP CX ;Recover operator
POP BX ;Recover current value
XCHG DX,BX
AND CH,AL
OR AL,AL ;Is it register or undefined label?
JZ NOCON ;If so, then no constant part
CMP CL,"-" ;Subtract it?
JNZ ADD
NEG BX
ADD:
ADD DX,BX
NEXTERM:
MOV AL,[SYM]
CMP AL,'+'
JZ PLSMNS
CMP AL,'-'
JZ PLSMNS
MOV AL,CH
RET
NOCON:
CMP CL,"-"
JNZ NEXTERM
BADOP:
MOV CL,5
JMP ERROR
TERM:
CALL FACTOR
MULOP:
PUSH DX ;Save value
PUSH AX ;Save type
CALL GETSYM
POP CX
CMP AL,"*"
JZ GETFACT
CMP AL,"/"
JNZ ENDTERM
GETFACT:
OR CL,CL ;Can we operate on this type?
JZ BADOP
PUSH AX ;Save operator
CALL GETSYM ;Get past operator
CALL FACTOR
OR AL,AL
JZ BADOP
POP CX ;Recover operator
POP BP ;And current value
XCHG AX,BP ;Save AH in BP
CMP CL,"/" ;Do we divide?
JNZ DOMUL
OR DX,DX ;Dividing by zero?
MOV CL,29H
JZ ERR2
MOV BX,DX
XOR DX,DX ;Make 32-bit dividend
DIV AX,BX
JMPS NEXFACT
DOMUL:
MUL AX,DX
NEXFACT:
MOV DX,AX ;Result in DX
XCHG AX,BP ;Restore flags to AH
MOV AL,-1 ;Indicate a number
JMPS MULOP
ENDTERM:
POP DX
MOV AL,CL
RET
FACTOR:
MOV AL,[SYM]
CMP AL,CONST
JZ RET
CMP AL,UNDEFID
JZ UVAL
CMP AL,"("
JZ PAREN
CMP AL,'"'
JZ STRING
CMP AL,"'"
JZ STRING
CMP AL,XREG ;Only 16-bit register may index
MOV CL,20
JNZ ERR2
TEST AH,1 ;Check to see if indexing is OK
MOV CL,1
JZ ERR2
MOV AL,DL
MOV CL,3
SUB AL,3 ;Check for BX
JZ BXJ
SUB AL,2 ;Check for BP
JZ BPJ
DEC AL ;Check for SI
MOV CL,4
JZ SIJ
DEC AL ;Check for DI
JZ DIJ
MOV CL,2 ;Invalid base/index register
ERR2: JMP ERROR
DIJ:
OR AH,20H ;Flag seeing index register DI
SIJ:
TEST AH,10H ;Check if already seen index register
JNZ ERR2
OR AH,10H ;Flag seeing index register
RET
BPJ:
OR AH,40H ;Flag seeing base register BP
BXJ:
TEST AH,80H ;Check if already seen base register
JNZ ERR2
OR AH,80H ;Flag seeing base register
RET
PAREN:
CALL GETSYM ;Eat the "("
CALL EXPRESSION
CMP B,[SYM],")" ;Better have closing paren
MOV CL,20
JNZ ERR30
RET
UVAL:
MOV CL,6
TEST AH,8 ;Check if undefined label has been seen
JNZ ERR30
OR AH,8 ;Flag seeing undefined label
MOV [UNDEF],BX
RET
ERR30: JMP ERROR
STRING:
MOV CH,AL
MOV AL,[CHR]
CMP AL,CH
MOV CL,35
MOV DL,AL
MOV DH,0
JNZ L0003
CALL ZERLEN
L0003:
CALL GETCHR
MOV CL,37
TEST AH,2
JZ ERR30
TEST AH,4
MOV CL,38
JNZ ERR30
STRGDAT:
MOV AL,DL
CMP AL,EOL
MOV CL,39
JZ ERR30
CALL PUT
MOV AL,[DATSIZ]
OR AL,AL
JNZ BYTSIZ
MOV AL,DH
CALL PUT
BYTSIZ:
MOV AL,[CHR]
MOV DL,AL
CALL GETCHR
JP STRGDAT
ZERLEN:
CALL NEXTCHR
CMP AL,CH
JNZ ERR30
RET
GETCHR:
CALL NEXTCHR
CMP AL,CH
JNZ RET
CALL NEXTCHR
CMP AL,CH
JZ RET
POP BX ;Kill return address to STRGDAT loop
MOV AL,-1 ;Flag type as constant
RET
GETSYM:
; The lexical scanner. Used only in the operand field. Returns with the token
; in SYM and AL, sometimes with additional info in BX or DX.
;
; AL=SYM=0 Undefined label. BX has pointer to information fields.
;
; AL=SYM=1 Constant (or defined label). DX has value.
;
; AL=SYM=2,3,4 8-bit register, 16-bit register, or segment register,
; respectively. DL has register number.
;
; AL=SYM=5 A mode flag (such as "B" for byte operation). Type of flag in DL
; and also stored in FLAG: -1=no flags, 0=B, 1=W, 2=S, 3=L, 4=T.
;
; AL=SYM=6 8087 floating point register, ST(n) or ST. DL has register number.
;
; All other values are the ASCII code of the character. Note that this may
; never be a letter or number.
PUSH AX ;Save AH
CALL GETSY
POP AX
MOV AL,[SYM]
RET
SCANB:
MOV AL,[CHR]
SCANT:
CMP AL,' '
JZ NEXB
CMP AL,9
JNZ RET
NEXB:
CALL NEXTCHR
JP SCANT
DOLLAR:
MOV DX,[OLDPC]
MOV AL,CONST
MOV [SYM],AL
NEXTCHJ:
JMP NEXTCHR
GETSY:
CALL SCANB
CMP AL,'$'
JZ DOLLAR
MOV [SYM],AL
OR AL,20H
CMP AL,'z'+1
JNC NEXTCHJ
CMP AL,'a'
JC $+5
JMP LETTER
CMP AL,'9'+1
JNC NEXTCHJ
CMP AL,'0'
JC NEXTCHJ
MOV BX,SYM
MOV B,[BX],CONST
CALL READID
DEC BX
MOV AL,[BX]
MOV CL,7
MOV BX,0
CMP AL,'h'
JNZ $+5
JMP HEX
INC CL
MOV [IX],ID
DEC:
MOV SI,[IX]
MOV AL,[SI]
INC [IX]
CMP AL,'9'+1
JC $+5
JMP ERROR
SUB AL,'0'
MOV DX,BX
SHL BX
SHL BX
ADD BX,DX
SHL BX
MOV DL,AL
MOV DH,0
ADD BX,DX
DEC CH
JNZ DEC
XCHG DX,BX
RET
HEX:
MOV DX,ID
DEC CH
HEX1:
MOV SI,DX
LODB
INC DX
SUB AL,'0'
CMP AL,10
JC GOTIT
CMP AL,'g'-'0'
JNC ERR4
SUB AL,'a'-10-'0'
GOTIT:
SHL BX
SHL BX
SHL BX
SHL BX
ADD BL,AL
DEC CH
JNZ HEX1
XCHG DX,BX
RET
ERR4: JMP ERROR
GETLET:
CALL SCANB
CMP AL,EOL
STC
JZ RET
CMP AL,';'
STC
JZ RET
MOV CL,10
OR AL,20H
CMP AL,'a'
JC ERR4
CMP AL,'z'+1
JNC ERR4
READID:
MOV BX,ID
MOV CH,0
MOREID:
MOV [BX],AL
INC CH
INC BX
CALL NEXTCHR
CMP AL,'0'
JC NOMORE
OR AL,20H
CMP AL,'z'+1
JNC NOMORE
CMP AL,'9'+1
JC MOREID
CMP AL,'a'
JNC MOREID
NOMORE:
MOV CL,AL
MOV AL,CH
MOV [LENID],AL
OR AL,AL
MOV AL,CL
RET
LETTER:
CALL READID
MOV AL,CH
DEC AL
JNZ NOFLG
MOV AL,[ID]
MOV CX,5
MOV DI,FLGTAB
UP
REPNE
SCAB ;See if one of B,W,S,L,T
JZ SAVFLG ;Go save flag
XOR AL,AL
MOV CH,[LENID]
NOFLG:
DEC AL
PUSH BX
JNZ L0004
CALL REGCHK
L0004:
POP BX
MOV AL,DH
JZ SYMSAV
CALL LOOKRET
SYMSAV:
MOV [SYM],AL
RET
SAVFLG:
MOV DL,CL ;Need flag type in DL
XCHG [FLAG],CL
CMP CL,-1
MOV CL,32
MOV AL,5
JZ SYMSAV
ERRJ3: JMP ERROR
FLGTAB: DB "tlswb"
FPREG:
;Have detected "ST" for 8087 floating point stack register
MOV DL,0 ;Default is ST(0)
CALL SCANB ;Get next character
CMP AL,"(" ;Specifying register number?
JNZ HAVREG
;Get register number
CALL NEXTCHR ;Skip over the "("
CALL GETOP ;A little recursion never hurt anybody
CMP AL,CONST ;Better have found a constant
MOV CL,20 ;Operand error if not
JNZ ERRJ3
CMP [DLABEL],0 ;Constant must be defined
MOV CL,30
JNZ ERRJ3
MOV DX,[DATA] ;Get constant
CMP DX,7 ;Constant must be in range 0-7
MOV CL,31
JA ERRJ3
MOV AL,[SYM]
CMP AL,")"
MOV CL,24
JNZ ERRJ3
HAVREG:
MOV DH,FREG
XOR AL,AL ;Zero set means register found
RET
REGCHK:
MOV BX,ID
CMP [BX],"s"+7400H ;"st"
JZ FPREG
MOV CL,[BX]
INC BX
MOV AL,[BX]
MOV BX,REGTAB
MOV DH,XREG
MOV DL,0
CMP AL,'x'
JZ SCANREG
MOV DH,REG
CMP AL,'l'
JZ SCANREG
MOV DL,4
CMP AL,'h'
JZ SCANREG
MOV DH,SREG
MOV DL,0
MOV BX,SEGTAB
CMP AL,'s'
JZ SCANREG
MOV DH,XREG
CMP AL,'p'
JZ PREG
CMP AL,'i'
JNZ RET
MOV DL,6
MOV AL,CL
CMP AL,'s'
JZ RET
INC DL
CMP AL,'d'
RET
PREG:
MOV DL,4
MOV AL,CL
CMP AL,'s'
JZ RET
INC DL
CMP AL,'b'