The assembly process

A student trying to get started on the first programming assignment, had sent me
email last night.  In class today, we cleared up Case A.  He writes again:

	Dr. Patt,

	Please disregard Case A, as it is clear that MUL is a valid label and R0 is the
	invalid instruction. The error code can be correctly returned. Please consider
	Case B alone.

	.ORIG x1000

	being a valid label for 0x1000 but not an illegal mnemonic.

	Thank you for your time and sorry about Case A.

	<<name withheld to protect the student who is rarin to get started>>

He had earlier written:

	> Dr. Patt,
	> We were going through the lab assignment page.
	> It says: "An invalid opcode (mnemonic) is one that is not defined in the
	> LC-3b
	> ISA."
	> eg.) Case A:
	> .ORIG x1000
	> MUL R0, R1, R2
	> .END
	> or Case B:
	> .ORIG x1000
	> ABC
	> .END
	> Questions
	> ---------
	> a) We do not understand why Case A has to be seen as an invalid mnemonic but
	> not
	> as an invalid label i.e., a label which has garbage after the tokenizing
	> character ' '.
	> b) In Case B, ABC could just be a label for location 0x1000 and the assembler
	> need not report an error. The user could later use .FILL to put a valid
	> opcode at 0x1000.

A few things to say: First, certainly we could allow a label to stand by 
itself and just add another symbolic name for the same entry, such as:

		  .ORIG	x4000

Then both ONE and ANOTHER_ONE would both be identified with the address x4000.

I say, we COULD have done that.  We chose to NOT do that, and make the Assembler
less clever, and easier for you to write.  Our rules are that, expect for lines 
that are just comments, every line must contain an OPCODE and OPERANDS.

So, a label by itself is not a valid Assembly Language statement according to our rules.
Given the rules of a valid statement on each line, ABC gets identified as a label,
and the procedure next looks for an opcode.  Since it can not find one, it barfs back
an illegal opcode code.  

Second, I do not understand your comment about the user later using .FILL to put a
valid opcode at 0x1000.  I do not understand how you feel that can be done.  The
assembly process happens before the program is run.  Once the assembler sees the .end, 
the assembler terminates the source string.  Who is the "user" and how do you propose
the .FILL can be used to later insert a proper instruction? 
	> c) Thirdly, a real coding error (typo) could still be a valid label. Instead
	> of
	> HALT if the user writes SALT, the code needn't be an illegal mnemonic but can
	> be a valid label.

Sure.  If the programmer wrote SALT, it would be interpreted as a label, even if it is
really a misspelling of HALT.  In fact, unfortunately, all assemblers (and compilers)
have instances where the assembler (or compiler) writer misinterpreted the intent of
the programmer and generated an error message that was off the mark.

So, if the programmer had written SALT, intending it to be HALT, the assembler would
pick it up as a legitimate label, and then look for an opcode (unsuccessfully).

Good luck with the course.

Yale Patt

	> Thank you for your time.
	> Sincerely,
	> <<name withheld>>