; Seattle Computer Products 8086 Assembler  version 2.00
;   by Tim Paterson
; Runs on the 8086 under 86-DOS

SYMWID:	EQU	10
FCB:	EQU	5CH
BUFSIZ:	EQU	128
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
DELETE:	EQU	19
READ:	EQU	20
SETDMA:	EQU	26
MAKE:	EQU	22
SEQWRT:	EQU	21

;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

	ORG	100H
	PUT	100H

	JMP	BEGIN

CPYRHT:	DB	'Copyright 1979 by Seattle Computer Products, Inc.'
	DB	13,10,13,10,'$'

BEGIN:
	MOV	SP,STACK
	MOV	DX,HEADER
	MOV	CL,PRINTMES
	CALL	SYSTEM
	MOV	DX,CPYRHT
	CALL	SYSTEM
	MOV	AL,[FCB+17]
	MOV	[SYMFLG],AL	;Save symbol table request flag
	MOV	BX,FCB+9	;Point to file extension
	MOV	AL,[BX]		;Get source drive letter
	CALL	CHKDSK		;Valid drive?
	OR	AL,AL
	JZ	DEFAULT		;If no extension, use existing drive spec
	MOV	[FCB],AL
DEFAULT:
	INC	BX
	MOV	AL,[BX]		;Get HEX file drive letter
	CMP	AL,'Z'		;Suppress HEX file?
	JZ	L0000
	CALL	CHKDSK
L0000:	
	MOV	[HEXFCB],AL
	INC	BX
	MOV	AL,[BX]		;Get PRN file drive letter
	CMP	AL,'Z'		;Suppress PRN file?
	JZ	NOPRN
	CMP	AL,'X'		;PRN file to console?
	JZ	NOPRN
	CALL	CHKDSK
NOPRN:
	MOV	[LSTFCB],AL
	CALL	ADDEXT
	MOV	DX,FCB
	MOV	CL,OPEN
	CALL	SYSTEM
	MOV	BX,NOFILE
	INC	AL
	JNZ	$+5
	JMP	PRERR
	XOR	AL,AL
	MOV	[FCB+32],AL	;Zero Next Record field
	MOV	DX,HEXFCB
	CALL	MAKFIL
	MOV	DX,LSTFCB
	CALL	MAKFIL
	MOV	BX,0FFH
	XCHG	BX,[HL]
	XCHG	DX,[DE]
	XCHG	CX,[BC]
	MOV	BX,START+1	;POINTER TO NEXT BYTE OF INTERMEDIATE CODE
	MOV	[CODE],BX
	MOV	[IY],START	;POINTER TO CURRENT RELOCATION BYTE
	MOV	BX,0
	MOV	[PC],BX		;DEFAULT PROGRAM COUNTER
	MOV	[BASE],BX	;POINTER TO ROOT OF ID TREE=NIL
	MOV	[RETPT],BX	;Pointer to last RET record
	DEC	BX
	MOV	[LSTRET],BX	;Location of last RET
	MOV	BX,[6]		;HL=END OF MEMORY
	MOV	[HEAP],BX	;BACK END OF SYMBOL TABLE SPACE
	MOV	AL,4
	MOV	[BCOUNT],AL	;CODE BYTES PER RELOCATION BYTE
	XOR	AL,AL
	MOV	[IFFLG],AL	;NOT WITHIN IF/ENDIF
	MOV	[CHKLAB],AL	;LOOKUP ALL LABELS

;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:
	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:
	XCHG	DX,BX
	MOV	CL,PRINTMES
	CALL	SYSTEM
	JMP	0

MAKFIL:
	MOV	SI,DX
	LODB			;Get drive select byte
	CMP	AL,20H		;If not valid, don't make file
	JNC	RET
	PUSH	DX
	INC	DX
	MOV	BX,FCB+1
	MOV	CX,8
	UP
	MOV	SI,BX
	MOV	DI,DX
	REP
	MOVB			;Copy source file name
	MOV	DX,DI
	MOV	BX,SI
	POP	DX
	MOV	CL,DELETE
	CALL	SYSTEM
	MOV	CL,MAKE
	CALL	SYSTEM
	MOV	BX,NOSPAC
	INC	AL		;Success?
	JZ	PRERR
	MOV	CL,OPEN
	JMP	SYSTEM

ADDEXT:
	MOV	DX,FCB+9
	MOV	BX,EXTEND	;Set extension to ASM
	MOV	CX,7
	UP
	MOV	SI,BX
	MOV	DI,DX
	REP
	MOVB
	MOV	DX,DI
	MOV	BX,SI
	RET

CHKDSK:
	SUB	AL,' '		;If not present, set zero flag
	JZ	RET
	SUB	AL,20H
	JZ	DSKERR		;Must be in range A-W
	CMP	AL,'X'-'@'
	JC	RET
DSKERR:
	MOV	BX,BADDSK
	JP	PRERR

ERROR:
	MOV	AL,CL
	JMP	ENDLIN

NEXTCHR:
	XCHG	BX,[HL]
	XCHG	DX,[DE]
	XCHG	CX,[BC]
	INC	BL
	JNZ	GETCH
;Buffer empty so refill it
	MOV	DX,80H
	MOV	CL,SETDMA
	CALL	SYSTEM
	XCHG	DX,BX
	MOV	DX,FCB
	MOV	CL,READ
	CALL	SYSTEM
	OR	AL,AL
	MOV	AL,1AH		;Possibly signal End of File
	JNZ	NOMOD		;If nothing read
GETCH:
	MOV	AL,[BX]
NOMOD:
	XCHG	BX,[HL]
	XCHG	DX,[DE]
	XCHG	CX,[BC]
	MOV	[CHR],AL
	RET


MROPS:
	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?
	RCR	SI
	TEST	CL,1		;Check if register-to-register operation OK
	RCL	SI
	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
	RCR	SI
	TEST	CL,8		;Check if segment register OK
	RCL	SI
	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
	AND	CH,0FDH		;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:
	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	BX,[CON]	;Defined part
	MOV	[DATA],BX
	MOV	BX,[UNDEF]	;Undefined part
	MOV	[DLABEL],BX
	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:
	CALL	GETSYM
	CMP	AL,','
	JZ	GETOP
	JP	GETOP1


GETVAL:
	LAHF
	XCHG	AX,BP
	SAHF
	PUSH	BX
	MOV	BX,0
	MOV	[CON],BX
	MOV	[UNDEF],BX
	POP	BX
	MOV	AL,[SYM]
	CMP	AL,'+'
	JZ	PLSMNS
	CMP	AL,'-'
	JZ	PLSMNS
	MOV	CH,'+'
	PUSH	CX
	JP	OPERATE
PLSMNS:
	LAHF
	XCHG	AH,AL
	PUSH	AX
	XCHG	AH,AL
	LAHF
	XCHG	AX,BP
	SAHF
	LAHF
	OR	AL,4		;Flag that a sign was found
	SAHF
	LAHF
	XCHG	AX,BP
	SAHF
	CALL	GETSYM
OPERATE:
	CMP	AL,CONST
	JNZ	$+5
	JMP	CVAL
	CMP	AL,UNDEFID
	JNZ	$+5
	JMP	UVAL
	CMP	AL,'"'
	JNZ	$+5
STRINGJ:JMP	STRING
	CMP	AL,"'"
	JZ	STRINGJ
	CMP	AL,XREG		;Only 16-bit register may index
	MOV	CL,20
	JNZ	ERR2
	LAHF
	XCHG	AX,BP
	SAHF
	RCR	SI
	TEST	AL,1		;Check to see if indexing is OK
	RCL	SI
	MOV	CL,1
	JZ	ERR2
	LAHF
	XCHG	AX,BP
	SAHF
	MOV	AL,DL
	MOV	CL,3
	CMP	AL,3		;Check for BX
	JZ	BXJ
	SUB	AL,5		;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:
	LAHF
	XCHG	AX,BP
	SAHF
	RCR	SI
	TEST	AL,10H		;Check if already seen index register
	RCL	SI
	JNZ	ERR2
	OR	AL,30H		;Flag seeing index register DI
	JP	LPCHK
SIJ:
	LAHF
	XCHG	AX,BP
	SAHF
	RCR	SI
	TEST	AL,010H		;Check if already seen index register
	RCL	SI
	JNZ	ERR2
	LAHF
	OR	AL,010H		;Flag seeing index register SI
	SAHF
	JP	LPCHK
BXJ:
	LAHF
	XCHG	AX,BP
	SAHF
	RCR	SI
	TEST	AL,080H		;Check if already seen base register
	RCL	SI
	JNZ	ERR2
	LAHF
	OR	AL,080H		;Flag seeing base register BX
	SAHF
	JP	LPCHK
BPJ:
	LAHF
	XCHG	AX,BP
	SAHF
	RCR	SI
	TEST	AL,080H		;Check if already seen base register
	RCL	SI
	JNZ	ERR2
	OR	AL,0C0H		;Flag seeing base register BP
LPCHK:
	LAHF
	XCHG	AX,BP
	SAHF
	POP	AX		;Get operator
	XCHG	AH,AL
	SAHF
	CMP	AL,'-'		;Can't subtract a register
	MOV	CL,5
	JZ	ERR2
NEXTER:
	LAHF
	XCHG	AX,BP
	SAHF
	LAHF
	OR	AL,4		;Flag that a term was processed
	SAHF
	LAHF
	XCHG	AX,BP
	SAHF
	CALL	GETSYM
	CMP	AL,'+'
	JNZ	$+5
PJ:	JMP	PLSMNS
	CMP	AL,'-'
	JZ	PJ
	LAHF
	XCHG	AX,BP
	SAHF
	MOV	CH,0
	RCR	SI
	TEST	AL,010H		;Test INDEX bit
	RCL	SI
	RCL	AL		;BASE bit (zero flag not affected)
	JZ	NOIND		;Jump if not indexed, with BASE bit in carry
	CMC
	RCL	CH
	RCL	AL		;BP bit
	RCL	CH
	RCL	AL		;DI bit
	RCL	CH		;The low 3 bits now have indexing mode
MODE:
	MOV	BX,[UNDEF]
	MOV	AL,BH
	OR	AL,BL
	LAHF
	OR	CH,080H		;If undefined label, force 16-bit displacement
	SAHF
	JNZ	RET
	MOV	BX,[CON]
	CALL	SIGNEXT		;Check if 8-bit with sign extended
	JNZ	RET		;If not, use 16-bit displacement
	LAHF
	AND	CH,07FH		;Reset 16-bit displacement
	SAHF
	LAHF
	OR	CH,040H		;Set 8-bit displacement
	SAHF
	MOV	AL,BH
	OR	AL,BL
	JNZ	RET		;Use it if not zero displacement
	MOV	AL,CH
	AND	AL,7		;Specify no displacement
	MOV	CH,AL
	CMP	AL,6		;Check for BP+0 addressing mode
	JNZ	RET
	LAHF
	OR	CH,040H		;If BP+0, use 8-bit displacement
	SAHF
	RET

SIGNEXT:
	MOV	AL,BH
	OR	AL,AL
	JZ	HIZERO
	INC	AL
	JNZ	RET
HIZERO:
	MOV	AL,BL
	XOR	AL,BH
	AND	AL,80H
	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

CVAL:
	MOV	BX,[CON]
	POP	AX
	XCHG	AH,AL
	SAHF
	CMP	AL,'-'
	JNZ	ADDCON
	SBB	BX,DX
SETCON:
	MOV	[CON],BX
	JMP	NEXTER
ADDCON:
	LAHF
	ADD	BX,DX
	RCR	SI
	SAHF
	RCL	SI
	JP	SETCON

UVAL:
	LAHF
	XCHG	AX,BP
	SAHF
	MOV	CL,6
	RCR	SI
	TEST	AL,008H		;Check if undefined label has been seen
	RCL	SI
	JNZ	ERR30
	LAHF
	OR	AL,008H		;Flag seeing undefined label
	XCHG	AX,BP
	SAHF
	MOV	[UNDEF],BX
	POP	AX
	XCHG	AH,AL
	SAHF
	CMP	AL,'+'		;Undefined label may only be added
	MOV	CL,5
ERR30:	JNZ	ERR3
	JMP	NEXTER


GETSYM:
	CALL	GETSY
	MOV	AL,[SYM]
	RET

SCANB:
	MOV	AL,[CHR]
SCANT:
	CMP	AL,' '
	JZ	N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	AL,DL
	STC
	JZ	RET
	XCHG	DX,BX
	JP	LOOK

LOOKRET:
	MOV	AL,CH
	CMP	AL,3	;RET has 3 letters
	JNZ	LOOKUP
	LAHF
	DEC	BX
	SAHF
	LAHF
	OR	B,[BX],080H
	SAHF
	MOV	DX,RETSTR+2
CHKRET:
	MOV	SI,DX
	LODB
	CMP	AL,[BX]
	JNZ	LOOKIT
	LAHF
	DEC	BX
	SAHF
	LAHF
	DEC	DX
	SAHF
	DEC	CH
	JNZ	CHKRET
	MOV	DX,[LSTRET]
	MOV	AL,DL
	AND	AL,DH
	INC	AL
	JZ	ALLRET
	MOV	BX,[PC]
	SBB	BX,DX
	CALL	SIGNEXT
	MOV	AL,1
	JZ	RET
ALLRET:
	MOV	BX,[RETPT]
	MOV	AL,BH
	OR	AL,BL
	MOV	AL,0
	JNZ	RET
	MOV	BX,[HEAP]
	LAHF
	DEC	BX
	SAHF
	LAHF
	DEC	BX
	SAHF
	LAHF
	DEC	BX
	SAHF
	MOV	[HEAP],BX
	XOR	AL,AL
	MOV	[BX],AL
	MOV	[RETPT],BX
	RET

LOOKUP:
	LAHF
	DEC	BX
	SAHF
	LAHF
	OR	B,[BX],080H
	SAHF
LOOKIT:
	MOV	BX,[BASE]
	MOV	AL,BH
	OR	AL,BL
	JZ	EMPTY
	CALL	LOOK
	JC	ENTER
	MOV	DX,4
	LAHF
	ADD	BX,DX
	RCR	SI
	SAHF
	RCL	SI
	MOV	AL,[BX]
	OR	AL,AL
	JZ	RET
	LAHF
	INC	BX
	SAHF
	MOV	DL,[BX]
	LAHF
	INC	BX
	SAHF
	MOV	DH,[BX]
	RET

ENTER:
	PUSH	BX		;Save pointer to link field
	CALL	CREATE		;Add the node
	POP	SI
	XCHG	SI,BX
	PUSH	SI
	MOV	[BX],DH		;Link new node
	LAHF
	DEC	BX
	SAHF
	MOV	[BX],DL
	POP	BX
	RET			;Zero was set by CREATE

EMPTY:
	CALL	CREATE
	MOV	[BASE],DX
	RET


CREATE:
	MOV	AL,[LENID]
	ADD	AL,8		;Storage needed for the node
	MOV	BX,[HEAP]
	MOV	DL,AL
	MOV	DH,0
	SBB	BX,DX		;Heap grows downward
	MOV	[HEAP],BX
	XCHG	DX,BX
	MOV	BX,[CODE]	;Check to make sure there's enough
	SBB	BX,DX
	JB	$+5
	JMP	ABORT
	PUSH	DX
	MOV	BX,LENID
	MOV	CL,[BX]
	INC	CL
	MOV	CH,0
	UP
	MOV	SI,BX
	MOV	DI,DX
	REP
	MOVB			;Move identifier and length into node
	MOV	DX,DI
	MOV	BX,SI
	MOV	CH,4
	XCHG	DX,BX
NILIFY:
	MOV	[BX],CL		;Zero left and right links
	INC	BX
	DEC	CH
	JNZ	NILIFY
	XOR	AL,AL		;Set zero flag
	MOV	[BX],AL		;Zero defined flag
	POP	DX		;Restore pointer to node
	RET

CPSLP:
	MOV	SI,DX
	LODB
	CMP	AL,[BX]
	LAHF
	INC	DX
	INC	BX
	SAHF
	JNZ	RET
	DEC	CH
	JNZ	CPSLP
	RET

GETLAB:
	MOV	BX,0
	MOV	[LABPT],BX
	MOV	AL,-1
	MOV	[FLAG],AL
	MOV	[LONG],AL
	MOV	DH,0
	MOV	AL,[CHR]
	CMP	AL,' '+1
	JC	NOT1
	LAHF
	OR	DH,001H
	SAHF
NOT1:
	CALL	GETLET
	JC	RET
	CMP	AL,':'
	JNZ	LABCHK
	CALL	NEXTCHR
	JP	LABEL
LABCHK:
	OR	AL,AL
	RCR	SI
	TEST	DH,001H
	RCL	SI
	JZ	RET
LABEL:
	MOV	AL,[CHKLAB]
	OR	AL,AL
	JZ	$+5
	JMP	GETLET
	CALL	LOOKUP
	MOV	CL,11
	JNZ	ERR5
	MOV	DX,[PC]
	MOV	B,[BX],1
	LAHF
	INC	BX
	SAHF
	MOV	[BX],DL
	MOV	[LABPT],BX
	LAHF
	INC	BX
	SAHF
	MOV	[BX],DH
	JMP	GETLET

ERR5:	JMP	ERROR

ASMLIN:
	MOV	BX,[PC]
	MOV	[OLDPC],BX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ROR
PUTBW:
	MOV	DX,[DLABEL]
	MOV	BX,[DATA]
PUTCHK:
	MOV	AL,DH
	OR	AL,DL
	JZ	NOUNDEF
	MOV	AL,DL
	CALL	PUTCD
	MOV	AL,DH
	CALL	PUTCD
	MOV	AL,BL
	CALL	PUTINC
	MOV	AL,BH
	RCR	SI
	TEST	CH,080H
	RCL	SI
	JZ	SMPUT
	CALL	GEN
	JP	PRET
SMPUT:
	CALL	PUTCD
	CALL	GEN1
PRET:
	POP	BX
	POP	DX
	POP	CX
	RET

NOUNDEF:
	MOV	AL,BL
	MOV	CL,BH
	PUSH	CX
	MOV	CH,0
	CALL	GEN
	POP	CX
	MOV	AL,CL
	RCR	SI
	TEST	CH,080H
	RCL	SI
	MOV	CH,0
	JZ	PRETJ
	CALL	GEN
PRETJ:	JP	PRET

PUTADD:
	PUSH	CX
	PUSH	DX
	PUSH	BX
	MOV	CH,0
	MOV	CL,AL
	CALL	GEN		;Save the addressing mode as pure code
	MOV	AL,CL
	MOV	CH,80H
	AND	AL,0C7H
	CMP	AL,6
	JZ	TWOBT		;Direct address?
	AND	AL,0C0H
	JZ	PRET		;Indirect through reg, no displacement?
	CMP	AL,0C0H
	JZ	PRET		;Register to register operation?
	MOV	CH,AL		;Save whether one- or two-byte displacement
TWOBT:
	MOV	BX,[ADDR]
	MOV	DX,[ALABEL]
	JP	PUTCHK

GRP2:
	CALL	GETOP
	MOV	CX,0FF30H
	CMP	AL,UNDEFID
	JZ	PMEM
	MOV	CH,50H
	CMP	AL,XREG
	JZ	PXREG
	MOV	CH,6
	CMP	AL,SREG
	JNZ	$+5
	JMP	PACKREG
	MOV	CL,20
	JMP	ERROR

PMEM:
	MOV	AL,CH
	CALL	PUT
	MOV	AL,CL
	OR	AL,DL
	JMP	PUTADD

PXREG:
	MOV	AL,CH
	OR	AL,DL
	JMP	PUT

GRP3:
	CALL	GETOP
	PUSH	DX
	CALL	GETOP2
	POP	BX
	MOV	CX,8614H
	MOV	AL,SREG
	CMP	AL,B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	VAL1
	MOV	AL,[SYM]
	CMP	AL,','
	MOV	AL,[DATSIZ]
	JNZ	ENDDAT
	CALL	SAVDAT
	JP	GETDAT
ENDDAT:
	CMP	AL,2
	JNZ	SAVDAT
	MOV	BX,[DATA]
	LAHF
	OR	BL,080H
	SAHF
	MOV	[DATA],BX
SAVDAT:
	OR	AL,AL
	JZ	$+5
	JMP	PUTBYT
	JMP	PUTWOR
IF:
	MOV	AL,BH
	OR	AL,BL
	MOV	AL,1
	JZ	SKIPCD
	MOV	[IFFLG],AL
	RET

SKIPCD:
	MOV	[CHKLAB],AL
SKIPLP:
	XOR	AL,AL
	CALL	NEXLIN
	CALL	NEXTCHR
	CMP	AL,1AH
	JZ	END
	CALL	GETLAB
	JC	SKIPLP
	MOV	BX,LENID
	MOV	DX,IFEND
	MOV	CH,[BX]
	INC	CH
	CALL	CPSLP
	JNZ	SKIPLP
	XOR	AL,AL
	MOV	[CHKLAB],AL
	RET

ENDIF:
	MOV	BX,IFFLG
	MOV	AL,[BX]
	MOV	B,[BX],0
	MOV	CL,36
	OR	AL,AL
	JZ	ERR11
	RET

;*********************************************************************
;
;	PASS 2
;
;*********************************************************************

END:
	MOV	CL,4
WREND:
	MOV	CH,0FFH
	MOV	AL,CH
	CALL	GEN
	DEC	CL
	JNZ	WREND
	MOV	AL,[LSTFCB]
	CMP	AL,'Z'
	JZ	NOREOPN
	CALL	ADDEXT
	MOV	DX,FCB
	MOV	CL,OPEN
	CALL	SYSTEM
	MOV	BX,0FFH
	XCHG	BX,[HL]
	XCHG	DX,[DE]
	XCHG	CX,[BC]
NOREOPN:
	MOV	AL,-5
	MOV	[HEXCNT],AL	;FLAG HEX BUFFER AS EMPTY
	MOV	[SKPFLG],AL
	MOV	BX,HEXBUF
	MOV	[HEXPNT],BX
	MOV	BX,LSTBUF
	MOV	[LSTPNT],BX
	MOV	BX,0
	MOV	[ERRCNT],BX
	MOV	[PC],BX
	MOV	BX,OBJECT
	MOV	[HEXADD],BX
	XOR	AL,AL
	MOV	[FCB+20H],AL	;Set NEXT RECORD field to zero
	MOV	[COUNT],AL
	CALL	STRTLIN
	MOV	BX,START
NEXBT:
	MOV	CH,4
	MOV	CL,[BX]		;Get flag byte
	LAHF
	INC	BX		;Point to code
	SAHF
CDLP:
	RCL	CL		;Get high bit
	JC	TESTTYP		;Word fixup or special
	RCL	CL
	JNC	$+5
	JMP	DEFBYT		;Byte fixup
	MOV	AL,[BX]
OBJBT:
	CALL	SAVCD
NEXCD:
	INC	BX
	DEC	CH		;Still have codes left?
	JNZ	CDLP
	JP	NEXBT
TESTTYP:
	RCL	CL
	JC	$+5
	JMP	DEFWRD
	MOV	AL,[BX]
	CMP	AL,-10
	JC	$+5
	JMP	SPCFUN
	PUSH	CX
	PUSH	BX
	MOV	BX,COUNT
	MOV	AL,6
	SUB	AL,[BX]
	MOV	B,[BX],0
	MOV	CH,AL
	MOV	AL,' '
	JZ	NOFIL
BLNK:				;Put in 3 blanks for each byte not present
	CALL	LIST
	CALL	LIST
	CALL	LIST
	DEC	CH
	JNZ	BLNK
NOFIL:
	CALL	OUTLIN
	POP	BX
	MOV	AL,[BX]
	PUSH	BX
	CALL	REPERR
	MOV	AL,[ERR]
	CALL	REPERR
	CALL	STRTLIN
	POP	BX
	POP	CX
	JP	NEXCD

OUTLIN:
	CALL	LIST
	MOV	AL,[LSTFCB]
	CMP	AL,'Z'
	JZ	RET
	MOV	BX,LINFLG
	MOV	AL,[BX]
	MOV	B,[BX],-1
	OR	AL,AL
	JNZ	CRLF		;Output line only if first time
OUTLN:
	CALL	NEXTCHR
	CALL	LIST
	CMP	AL,10		;Output until linefeed found
	JNZ	OUTLN
	RET

PRTCNT:
	MOV	BX,ERCNTM
	CALL	PRINT
	MOV	BX,[ERRCNT]
	CALL	CONV10
	CALL	PRNT10
CRLF:
	MOV	AL,13
	CALL	LIST
	MOV	AL,10
	JMP	LIST

DEFBYT:
	CALL	FIXUP
	XCHG	DX,BX
	CALL	SIGNEXT		;See if in range +127 to -128
	XCHG	DX,BX
	JZ	OBJBTE		;If so, it's always OK
	MOV	AL,DH
	OR	AL,AL		;Check for range +255 to -256
	JZ	CHKJMP
	INC	AL
	JZ	CHKJMP
RNGERR:
	MOV	AL,101		;Value out of range
	MOV	[ERR],AL
OBJBTE:
	MOV	AL,DL
	JMP	OBJBT
CHKJMP:
;Check for short jump. If so, we're out of range; otherwise we're OK
	MOV	AL,[COUNT]
	DEC	AL		;Only one other byte on line?
	JNZ	OBJBTE		;Can't be short jump if not
	MOV	AL,[PREV]	;Get the first byte of this line
	CMP	AL,0EBH		;Direct short jump?
	JZ	RNGERR
	AND	AL,0FCH
	CMP	AL,0E0H		;LOOP or JCXZ instruction?
	JZ	RNGERR
	AND	AL,0F0H
	CMP	AL,70H		;Conditional jump?
	JZ	RNGERR
	JP	OBJBTE

DEFWRD:
	CALL	FIXUP
	MOV	AL,DL
	CALL	SAVCD
	MOV	AL,DH
	JMP	OBJBT

FIXUP:
	PUSH	CX
	MOV	DL,[BX]		;Get pointer to symbol
	LAHF
	INC	BX
	SAHF
	MOV	DH,[BX]
	LAHF
	INC	BX
	SAHF
	XCHG	DX,BX
	MOV	AL,[BX]		;Whether symbol was defined
	LAHF
	INC	BX
	SAHF
	MOV	CL,[BX]		;Get symbol value
	LAHF
	INC	BX
	SAHF
	MOV	CH,[BX]
	XCHG	DX,BX
	MOV	DL,[BX]		;Get constant part
	LAHF
	INC	BX
	SAHF
	MOV	DH,[BX]
	XCHG	DX,BX
	LAHF
	ADD	BX,CX		;Add symbol value to constant part
	RCR	SI
	SAHF
	RCL	SI
	POP	CX
	XCHG	DX,BX
	OR	AL,AL		;See if symbol got defined
	JNZ	RET
	MOV	AL,100		;Undefined - flag error
	MOV	[ERR],AL
	MOV	DX,0
	RET

STRTLIN:
	XOR	AL,AL
	MOV	[ERR],AL
	MOV	[LINFLG],AL
	MOV	BX,[PC]
	MOV	AL,BH
	CALL	PHEX
	MOV	AL,BL
PHEXB:
	CALL	PHEX
	MOV	AL,' '
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OK:
	MOV	DH,AL
WRTSYM:
	MOV	AL,[BX]
	LAHF
	INC	BX
	SAHF
	CALL	LIST
	DEC	CH
	JNZ	WRTSYM
	MOV	CH,DH
	INC	CH
	MOV	AL,' '
OUTB:
	CALL	LIST
	DEC	CH
	JNZ	OUTB
	LAHF
	INC	BX
	SAHF
	LAHF
	INC	BX
	SAHF
	PUSH	BX
	LAHF
	INC	BX
	SAHF
	LAHF
	INC	BX
	SAHF
	LAHF
	INC	BX
	SAHF
	LAHF
	INC	BX
	SAHF
	MOV	AL,[BX]
	CALL	PHEX
	LAHF
	DEC	BX
	SAHF
	MOV	AL,[BX]
	CALL	PHEX
	CALL	CRLF
	POP	BX
	MOV	DL,[BX]
	LAHF
	INC	BX
	SAHF
	MOV	DH,[BX]
	MOV	AL,DH
	OR	AL,DL
	JNZ	NODE
	RET

CONV10:
	MOV	CH,16
	MOV	DX,0
CONVLP:
	LAHF
	ADD	BX,BX
	RCR	SI
	SAHF
	RCL	SI
	MOV	AL,DL
	ADC	AL,AL
	DAA
	MOV	DL,AL
	MOV	AL,DH
	ADC	AL,AL
	DAA
	MOV	DH,AL
	RCL	CL
	DEC	CH
	JNZ	CONVLP
	RET

PRNT10:
	XCHG	DX,BX
	MOV	CH,'0'-' '	;Enable leading zero suppression
	MOV	AL,CL
	CALL	LODIG
	MOV	AL,BH
	CALL	HIDIG
	MOV	AL,BH
	CALL	LODIG
	MOV	AL,BL
	CALL	HIDIG
	MOV	AL,BL
	MOV	CH,0		;Don't suppress last digit
LODIG:
	CALL	LHALF
DIGIT:
	CMP	AL,'0'
	JZ	SUPZ
	MOV	CH,0		;Turn off zero suppression if not zero
SUPZ:
	SUB	AL,CH		;Convert leading zeros to blanks
	JMP	LIST

HIDIG:
	CALL	UHALF
	JP	DIGIT

HEXEOF:
	MOV	AL,1AH
	CALL	PUTCHR
	JNZ	HEXEOF
	RET

SAVCD:
	MOV	[PREV],AL
	PUSH	BX
	PUSH	CX
	LAHF
	XCHG	AH,AL
	P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	NONE
	DW	NONE

HEADER:	DB	13,10,'Seattle Computer Products 8086 Assembler Version 2.00'
	DB	13,10,'$'
ERRMES:	DM	'***** ERROR no. '
NOSPAC:	DB	13,10,'No directory space',13,10,24H
ENDMES:	DM	'H',13,10
NOMEM:	DB	13,10,'Insufficient memory',13,10,'$'
NOFILE:	DB	13,10,'File not found',13,10,'$'
WRTERR:	DB	13,10,'Disk write error',13,10,'$'
BADDSK:	DB	13,10,'Bad disk specifier',13,10,'$'
ERCNTM:	DM	13,10,13,10,'Error Count ='
SYMMES:	DM	13,10,'Symbol Table',13,10,13,10
EXTEND:	DB	'ASM',0,0,0,0
IFEND:	DB	5,'endif'
RETSTR:	DM	'ret'
HEXFCB:	DB	0,'        HEX',0,0,0,0
	DS	16
	DB	0
LSTFCB:	DB	0,'        PRN',0,0,0,0
	DS	16
	DB	0
PC:	DS	2
OLDPC:	DS	2
LABPT:	DS	2
FLAG:	DS	1
LONG:	DS	1
ADDR:	DS	2
ALABEL:	DS	2
DATA:	DS	2
DLABEL:	DS	2
CON:	DS	2
UNDEF:	DS	2
LENID:	DS	1
ID:	DS	80
CHR:	DS	1
SYM:	DS	1
BASE:	DS	2
HEAP:	DS	2
SYMFLG:	DS	1
CODE:	DS	2
DATSIZ:	DS	1
RELOC:	DS	1
BCOUNT:	DS	1
COUNT:	DS	1
ERR:	DS	1
HEXPNT:	DS	2
HEXLEN:	DS	2
HEXADD:	DS	2
LASTAD:	DS	2
HEXCNT:	DS	1
CHKSUM:	DS	1
SKPFLG:	DS	1
LINFLG:	DS	1
PREV:	DS	1
IFFLG:	DS	1
CHKLAB:	DS	1
LSTPNT:	DS	2
ERRCNT:	DS	2
LSTRET:	DS	2
RETPT:	DS	2
HEXBUF:	DS	BUFSIZ+BUFSIZ
LSTBUF:	DS	BUFSIZ
BC:	DS	2
DE:	DS	2
HL:	DS	2
IX:	DS	2
IY:	DS	2
	DS	50
STACK:	EQU	$
START:	EQU	$
