english
version "1.0"
identify "xyz"

#: This module implements the microcontroller assembler assembler types.

module types

define assembler			#: Assembler
    record
	buffer string			#: Listing buffer
	byte_count unsigned		#: Bytes for current instruction
	debug_stream out_stream		#: Debug stream
	errors errors			#: Error count
	error_buffer string		#: Error buffer
	error_stream out_stream		#: Error output stream
	listing_stream out_stream	#: Listing stream
	memory_image memory_image	#: Memory image
	out_stream out_stream		#: Output stream
	pass unsigned			#: Assembler pass (1 or 2)
	program_counter unsigned	#: Current program counter
	standard_out out_stream		#: Standard output
	statement statement		#: Current statement
    generate allocate, erase, print

define assembler1[type1]		#: Assembler error type
    record
	zilch unsigned			#: Filler
    generate allocate, erase, print

define assembler2[type1, type2]		#: Assembler error type
    record
	zilch unsigned			#: Filler
    generate allocate, erase, print

define assembler3[type1, type2, type3]	#: Assembler error type
    record
	zilch unsigned			#: Filler
    generate allocate, erase, print

#define bit				#: Bit address
#    record
#	address expression		#: Address of bit
#	number unsigned			#: Bit number (0-7)
#    generate erase, new, print

define bit_address			#: Bit address
    record
	data_address unsigned		#: Data address
	bit_number unsigned		#: Bit number (0-7)
    generate allocate, erase, print

define binary				#: Binary opcode
    record
	expression1 expression		#: First expression
	expression2 expression		#: Second expression
    generate allocate, erase, print

define expression			#: Opcode expression argument 
    variant type expression_type	#: Expresion type
	add binary			#: Sum of two expressions
	bit_address binary		#: Bit address (aaa.b)
	character character		#: Character constant
	code_address unsigned		#: Code address
	data_address unsigned		#: Data address
	decimal unsigned		#: Unsigned decimal number
	hexadecimal unsigned		#: Unsigned hexadecimal number
	octal unsigned			#: Unsigned octal number
	string string			#: Quoted string
	subtract binary			#: Difference of two expressions
	symbol symbol			#: Symbolic value
    generate address_get, allocate, erase, print

define expression_type			#: Opcode expression type
    enumeration
	add				#: Sum of two expressions
	bit_address			#: Bit address (aaa.b)
	character			#: Character constant
	code_address			#: Code address
	data_address			#: Data address
	decimal				#: Unsigned decimal number
	hexadecimal			#: Unsigned hexadecimal number
	octal				#: Unsigned octal number
	string				#: Quoted string
	subtract			#: Difference of two expressions
	symbol				#: Symbolic value
    generate print

define memory_image			#: Memory image
    record
	bytes vector[unsigned]		#: Bytes of memory
	uninitialized unsigned		#: Uninitialized value
    generate allocate, erase, print

define reference			#: Symbol reference
    record
	address unsigned		#: Reference address
	size unsigned			#: Number of bytes of reference
	offset unsigned			#: Reference offset
    generate allocate, erase, print

define statement			#: One assembler statement
    record
	line_number unsigned		#: Statement line number
	opcode opcode			#: Opcode (never ??)
	comment string			#: Trailing comment (or ??)
    generate allocate, erase, print

define opcode				#: Opcode (or pseudo opcode)
    variant type opcode_type		#: Opcode type
	add expression			#: Add ins.
	add_carry expression		#: Add with carry ins.
	and binary			#: And ins.
	and_not expression		#: Bit and complement ins.
	blank bogus			#: Blank line
	byte expression			#: One byte constant
	call_absolute expression	#: Call to an 11-bit ins.
	call_long expression		#: Call to a 16-bit ins.
	clear expression		#: Clear ins.
	complement expression		#: Complement ins.
	decrement expression		#: Decrement ins.
	decimal_adjust bogus		#: BCD decimal adjust ins.
	divide bogus			#: Divide ins.
	end bogus			#: End psuedo opcode
	exchange expression		#: Exchange ins.
	exchange_nibble expression	#: Exchange nibble ins.
	comment string			#: Full-line comment line
	increment expression		#: Increment ins.
	jump_absolute expression	#: Jump to an 11-bit address ins.
	jump_bit binary			#: Jump if bit set ins.
	jump_bit_clear binary		#: Jump if bit set; clear bit ins.
	jump_carry expression		#: Jump if carry set ins.
	jump_compare_not_equal trinary	#: Jump if comparison not equal ins.
	jump_decrement_non_zero binary	#: Jump if decrement is non-zero ins.
	jump_indexed bogus		#: Jump indexed via accumulator ins.
	jump_long expression		#: Jump to a 16-bit address ins.
	jump_no_bit binary		#: Jump if bit set ins.
	jump_no_carry expression	#: Jump if carry not set ins.
	jump_non_zero expression	#: Jump if accumulator non-zero ins.
	jump_short expression		#: Jump a short relative distance ins.
	jump_zero expression		#: Jump if accumulator zero ins. 
	label expression		#: Code label
	multiply bogus			#: Mulitply ins.
	move binary			#: Move ins.
	move_code_pointer bogus		#: Move code using dptr ins.
	move_code_pc bogus		#: Move code using pc ins.
	move_external binary		#: Move data to external memory ins.
	nop bogus			#: No-operation ins.
	or binary			#: Or ins.
	or_not expression		#: Bit or complement ins.
	origin expression		#: Origin pseudo opcode
	pop expression			#: Pop expression from stack ins.
	push expression			#: Push byte onto stack ins.
	xreturn bogus			#: Return ins.
	return_interrupt bogus		#: Return from interrupt ins.
	rotate_left bogus		#: Rotate left ins.
	rotate_left_carry bogus		#: Rotate left through carry ins.
	rotate_right bogus		#: Rotate right ins.
	rotate_right_carry bogus	#: Rotate right through carry ins.
	set_bit expression		#: Set bit ins.
	swap bogus			#: Swap nibble ins.
	subtract_borrow expression	#: Subtract with borrow ins.
	word expression			#: One 2-byte constant
	xor binary			#: Xor ins.
    generate allocate, erase, print

define program				#: Program
    record
	debug_stream out_stream		#: Debugging stream
	statements vector[statement]	#: Program statements
	symbol_table symbol_table	#: Symbol table to use
    generate allocate, erase, print

define symbol				#: Assembler symbol
    record
	defined logical			#: {true}=>symbol defined
	line_number unsigned		#: line number where symbol is defined
	name string			#: Symbol name
	references vector[reference]	#: Symbol references
	value value			#: Symbol value (and type)
    generate allocate, erase, identical, print

define symbol_table			#: Symbol table
    record
	symbol symbol			#: Temporary symbol (for lookup)
	symbols vector[symbol]		#: List of all symbols
	table set[symbol]		#: Table
    generate allocate, erase, print

define trinary				#: Binary opcode
    record
	expression1 expression		#: First expression
	expression2 expression		#: Second expression
	expression3 expression		#: Third expression
    generate allocate, erase, print

define value				#: Expression value
    variant type value_type		#: Value type
	a bogus				#: A (Accumulator)
	c bogus				#: C (Carry flag)
	bit_address bit_address		#: aaa.b (Bit address)
	constant unsigned		#: #k (Constant)
	code_address unsigned		#: aaa (Code address)
	data_address unsigned		#: aaa (Data address)
	dptr bogus			#: DPTR (Data pointer)
	ri unsigned			#: @Ri (Register Indirect)
	rn unsigned			#: Register (Register)
	string string			#: String
	undefined bogus			#: Undefined (i.e. error)
    generate allocate, erase, identical, print

define value_type			#: Expression value type
    enumeration
	a				#: A (Accumulator)
	c				#: C (Carry flag)
	bit_address			#: aaa.b (Bit address)
	constant			#: #k (Constant)
	code_address			#: aaa (Code address)
	data_address			#: aaa (Data address)
	dptr				#: DPTR (Data pointer)
	ri				#: @Ri (Register Indirect)
	rn				#: Register (Register)
	string				#: String
	undefined			#: Undefined (i.e. error)
    generate print