english
version "1.0"
identify "xyz"

#: This module defines the basic 8051 SFR's.

module program


#: {program} routines:

procedure append@program
    takes
	program program
	comment string
    returns opcode

    #: This procedure will create a statement containing a newly created
    #, {opcode} and append it to {program}.  The new {opcode} is returned.
    #, The {opcode} is labeled with {comment}.


procedure binary@program
    takes
	program program
	expression1 expression
	expression2 expression
    returns binary

    #: This programe will create and return a {binary} object
    #, containing {expression1} and {expression2} created using {program}.


procedure bit_address_insert@program
    takes
	program program
	name string
	data_address unsigned
	bit_number unsigned
    returns_nothing

    #: This procedure will insert {name} into the symbol table of {program}
    #, as a bit at {data_address} with a bit number of {bit_number}.


procedure bit_addresses_insert@program
    takes
	program program
	name string
	data_address unsigned
	bit0_name string
	bit1_name string
	bit2_name string
	bit3_name string
	bit4_name string
	bit5_name string
	bit6_name string
	bit7_name string
    returns_nothing

    #: This procedure will insert {name} into {program} as a data address
    #, with an address of {dataa_address}.  Each of the bit registers named
    #, {bit0_name} through {bit7_name} are inserted as well, provided
    #, they are not equal to ??@{string}.


procedure create@program
    takes
	symbol_table symbol_table
	debug_stream out_stream
    returns program

    #: This procedure will `create' and return a new program object
    #, using {symbol_table}.

    #, the initial object.

procedure opcode_append@program
    takes
	program program
	opcode opcode
	comment string
    returns_nothing

    #: This procedure will create a statement containing {opcode} and
    #, optionally {comment} append it to {program}.


procedure output@program
    takes
	program program
	out_stream out_stream
    returns_nothing

    #: This procedure will output {program} to {out_stream}.


procedure data_address_insert@program
    takes
	program program
	name string
	data_address unsigned
    returns_nothing

    #: This procedure will insert {name} into {program} as a data addess
    #, with a value of {data_address}.


procedure statement_append@program
    takes
	program program
	statement statement
    returns_nothing

    #: This procedure will append {statement} to {program}.


procedure trinary@program
    takes
	program program
	expression1 expression
	expression2 expression
	expression3 expression
    returns trinary

    #: This programe will create and return a {binary} object
    #, containing {expression1}, {expression2}, and {expression3} created
    #, using {program}.


# Opcode routines:

procedure acall@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a call to an 11-bit address  instruction.


procedure add@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an add instruction.


procedure addc@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an add with carry instruction.


procedure ajmp@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an absolute jump to {expression}.


procedure anl@program
    takes
	program program
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate an and instruction.


procedure anl_not@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a bit and complement instruction.


procedure blank@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a blank line.


procedure byte@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a byte statement containing
    #, {expression}.


procedure comment@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a full-line comment containing
    #, {comment}.


procedure cjne@program
    takes
	program program
	expression1 expression
	expression2 expression
	expression3 expression
	comment string
    returns_nothing

    #: This procedure will generate a jump compare not-equal instruction.


procedure clr@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a clear instruction.


procedure cpl@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a complement instruction.


procedure da@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a decimal adjust instruction.


procedure dec@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a decrement instruction.


procedure div@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a divide instruction.


procedure djnz@program
    takes
	program program
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate a jump decrement non-zero instruction.


procedure end@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate an end pseudo append@(program, comment).


procedure ijmp@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a long jump to {expression}.


procedure inc@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an increment instruction.


procedure jb@program
    takes
	program program
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if bit set instruction.


procedure jbc@program
    takes
	program program
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if bit set and clear instruction.


procedure jc@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if carry set instruction.


procedure jnb@program
    takes
	program program
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if bit not set instruction.


procedure jnc@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if carry not set instruction.


procedure jnz@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if non-zero instruction.


procedure jz@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if zero instruction.


procedure xlabel@program
    takes
	program program
	label_name expression
	comment string
    returns_nothing

    #: This procedure will generate a label definition line containing
    #, {label_name}.  {label_name} must be an {expression} of type {symbol}.


procedure lcall@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a call to a 16-bit address  instruction.


procedure ljmp@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a long jump to {expression}.


procedure mul@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a multiply instruction.


procedure mov@program
    takes
	program program
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate a move instruction.


procedure movcdptr@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a move code with dptr instruction.


procedure movcpc@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a move code iwht pc instruction.


procedure movx@program
    takes
	program program
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate a move external instruction.


procedure nop@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a no-operation instruction.


procedure org@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will set the program counter origin.
    

procedure orl@program
    takes
	program program
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate an and instruction.


procedure orl_not@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an bit and complement instruction.


procedure pop@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a push opcode containing
    #, {expression}.


procedure push@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a push opcode containing
    #, {expression}.


procedure ret@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a return instruction.


procedure reti@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a return from interrupt left instruction.


procedure rl@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a rotate left instruction.


procedure rlc@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a rotate left through carry instruction.


procedure rr@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a rotate right instruction.


procedure rrc@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a rotate right through carry instruction.


procedure setb@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an set bit instruction.


procedure sjmp@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a short jump to {expression}.


procedure swap@program
    takes
	program program
	comment string
    returns_nothing

    #: This procedure will generate a swap nibble instruction.


procedure subb@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an subtract with borrow instruction.


procedure word@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a word of code data for {program}
    #, containing the constant {expression}.


procedure xch@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an exchange instruction for {program}
    #, exhanges the contents of the accumulator with the contents of
    #, {expression}.


procedure xchd@program
    takes
	program program
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an exchange nibble instruction for
    #, {program} that exchanges the 4-bit nibbles in {expression}.


procedure xrl@program
    takes
	program program
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate an xor instruction for {program}
    #, that computes the bit-wise exclusive OR of {expression1} and
    #, {expression2} and stores the result back into {expression1}.


#: Global routines that implement opcode functionality:

procedure acall
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a call to an 11-bit address  instruction.


procedure add
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an add instruction.


procedure addc
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an add with carry instruction.


procedure ajmp
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an absolute jump to {expression}.


procedure anl
    takes
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate an and instruction.


procedure anl_not
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a bit and complement instruction.


procedure blank
    takes
	comment string
    returns_nothing

    #: This procedure will generate a blank line.


procedure byte
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a byte statement containing
    #, {expression}.


procedure comment
    takes
	comment string
    returns_nothing

    #: This procedure will generate a full-line comment containing
    #, {comment}.


procedure cjne
    takes
	expression1 expression
	expression2 expression
	expression3 expression
	comment string
    returns_nothing

    #: This procedure will generate a jump compare not-equal instruction.


procedure clr
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a clear instruction.


procedure cpl
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a complement instruction.


procedure da
    takes
	comment string
    returns_nothing

    #: This procedure will generate a decimal adjust instruction.


procedure dec
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a decrement instruction.


procedure div
    takes
	comment string
    returns_nothing

    #: This procedure will generate a divide instruction.


procedure djnz
    takes
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate a jump decrement non-zero instruction.


procedure end
    takes
	comment string
    returns_nothing

    #: This procedure will generate an end pseudo 


procedure ijmp
    takes
	comment string
    returns_nothing

    #: This procedure will generate a long jump to {expression}.


procedure inc
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an increment instruction.


procedure jb
    takes
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if bit set instruction.


procedure jbc
    takes
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if bit set and clear instruction.


procedure jc
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if carry set instruction.


procedure jnb
    takes
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if bit not set instruction.


procedure jnc
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if carry not set instruction.


procedure jnz
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if non-zero instruction.


procedure jz
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an jump if zero instruction.


procedure xlabel
    takes
	label_name expression
	comment string
    returns_nothing

    #: This procedure will generate a label definition line containing
    #, {label_name}.  {label_name} must be an {expression} of type {symbol}.


procedure lcall
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a call to a 16-bit address  instruction.


procedure ljmp
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a long jump to {expression}.


procedure mul
    takes
	comment string
    returns_nothing

    #: This procedure will generate a multiply instruction.


procedure mov
    takes
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate a move instruction.


procedure movcdptr
    takes
	comment string
    returns_nothing

    #: This procedure will generate a move code with dptr instruction.


procedure movcpc
    takes
	comment string
    returns_nothing

    #: This procedure will generate a move code iwht pc instruction.


procedure movx
    takes
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate a move external instruction.


procedure nop
    takes
	comment string
    returns_nothing

    #: This procedure will generate a no-operation instruction.


procedure org
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will set the program counter origin.
    

procedure orl
    takes
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate an and instruction.


procedure orl_not
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an bit and complement instruction.


procedure pop
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a push opcode containing
    #, {expression}.


procedure push
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a push opcode containing
    #, {expression}.


procedure ret
    takes
	comment string
    returns_nothing

    #: This procedure will generate a return instruction.


procedure reti
    takes
	comment string
    returns_nothing

    #: This procedure will generate a return from interrupt left instruction.


procedure rl
    takes
	comment string
    returns_nothing

    #: This procedure will generate a rotate left instruction.


procedure rlc
    takes
	comment string
    returns_nothing

    #: This procedure will generate a rotate left through carry instruction.


procedure rr
    takes
	comment string
    returns_nothing

    #: This procedure will generate a rotate right instruction.


procedure rrc
    takes
	comment string
    returns_nothing

    #: This procedure will generate a rotate right through carry instruction.


procedure setb
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an set bit instruction.


procedure sjmp
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a short jump to {expression}.


procedure swap
    takes
	comment string
    returns_nothing

    #: This procedure will generate a swap nibble instruction.


procedure subb
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an subtract with borrow instruction.


procedure word
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate a word opcode containing
    #, {expression}.


procedure xch
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an exchange instruction.


procedure xchd
    takes
	expression expression
	comment string
    returns_nothing

    #: This procedure will generate an exchange nibble instruction.


procedure xrl
    takes
	expression1 expression
	expression2 expression
	comment string
    returns_nothing

    #: This procedure will generate an xor instruction.