Fri, 1 Feb 2013, 00:40

A student writes:

> Dear Prof. Patt,
> I have a short question regarding to lab 1.
> It is mentioned in the lab 1 assignment that:
> Note: your assembler needs to recognize only labels as operands for LEA, BR,
> and JSR instructions. For example, if the following line is in an input
>assembly language program, your assembler can exit with error code 4:
> 	LEA R1, x100
> However, I get confused in the following situation:
>         LEA R1, x1H0  or    LEA R1, #1S0     or     LEA R1, 100
> In the above cases, the second operand "looks like" numbers, but
> either do not follow the format exactly or have invalid digits. Should
> we consider them as "undefined label" and exit with error code 1, or
> still can consider them as numbers, and return with error code 4?
> Thanks sincerely,
> <<name withheld to protect the student struggling with undefined vs ill-formed>>

A few students have asked about this, so I think it is worth responding to all
of you.  Undefined is not the same as ill-formed (aka illegal).

Undefined label:

An undefined label is a label used in an instruction which is not tied to the
address of a memory location somewhere in the program.

For example, 

HOUSE   ADD  R1, R1, #2

is cool (as far as the assembly process is concerned, but

	.ORIG x9000

is not cool because the location HOUSE has not been specified.  i.e., the
address HOUSE is not defined.  Ergo HOUSE is an undefined label.

By the way, what will the "cool" two line segment above do?  Cool, as
in correct assembly language.  Not clear how useful the actual code will be.

Illegal (or, ill-formed) label:

An illegal label, or an ill-formed label is a label that violates the
constraints we have made on labels.  These constraints are necessary to
make sure every symbol is uniquely identifiable.  Computers do not tolerate

For example, 

ADD     ADD  R1, R1, #2

is an illegal label because one can not use opcodes as labels.  The Assembly
Language document lists all symbols that have other meanings and therefore
can not be used as labels.  The industry generally refers to the set of all
such symbols as "reserved words," and makes the statement: Reserved words can
not be used as labels.

Finally, one could write the following horrific code:

	.ORIG x3000

ADD is not only an illegal label, it is undefined.  What error message do
you report?  Answer: Whichever of two you wish.  Either will receive full 

Hope this helps.  Good luck finishing the lab on time.

Yale Patt