Fri, 6 Feb 2009, 21:27

A student writes (he found a problem with the "correct" assembler):

	Dr. Patt,

	Your example assembler does not seem to care if instructions go beyond
	the memory capacity of the LC-3. In other words, if there is an
	instruction at xFFFE, it seems to assume that the following
	instruction goes at x10000, an invalid memory address on the LC-3. 

Ouch!  This is a bug that should be fixed.  In fact, since the last 32
locations of the memory address space is reserved for I/O device registers,
the assembler should not produce code beyond xFFDF.  There should be an error
code to indicate there is no more memory space left.

We will fix it!  Thank you for pointing it out.

	My assembler simply wraps its internal line-counter around to x0000,
	which I think is what would happen in the PC of the LC-3 (although I
	confess I'm not sure about that).

Ooops!  Yes, you do NOT want to do that either.  The low address space is
used (typically) for data structures (like the interrupt vector table) used
by the operating system.  So a better solution would be for the assembler
to barf if the assembly language program goes beyond xFFDF.

	This becomes a problem when calculating offsets across that boundary.
	Take the following program:

	BR test
	test .fill xFF

	My assembler throws error code 4 with this code, because 'test' is all
	the way back at 0x0000, way too far away to express in 9 (or even 11)
	bits. Your assembler assembles it without complaint, outputting:


Shame on my assembler!

	So, my question is: will the PC wrap around in the "real" LC-3 and
	make the output from your assembler work correctly, or will there be
	an exception of some sort that would stop execution anyway?

No, the assembler should output an error message that you have exhausted
available memory if you go beyond xFFDF.

Since I do not want to make the assignment more complicated this late in the
game, our test cases will never test for this.  Next time I teach the course,
this will be corrected, AND we will generate test cases to test for it.

	Or, alternatively, can we assume that the input files will never try
	and put instructions outside of the valid range of memory addresses
	for the LC-3?

Yup, that is what we will do this time.

	<<name withheld to protect the student who found a bug in our assembler>

Thank you for pointing this out.  I am amazed this had not been caught before.

Yale Patt