Tue, 1 Oct 2013, 23:41



Another question that I think all of you need to be aware of.
A student writes:

 
> I have one more question actually. The program is supposed to start at
> x3000. I had to store some vectors in memory before that, so the "code"
> actually starts before x3000, but the actual instructions begins at x3000.
> Can I depend on whoever is testing the program to set the PC to x3000
> before running the program?
> Thank you.
> <<name withheld to protect the student who guarantees his program won't run>>


The short answer is: No, you can not.  In the real world of computers,
computers can only work on your program if the file containing your
program is presented to the computer in the way the computer expects 
it.  Otherwise the computer will process it as garbage.  

As I have said many times: computers do what you tell them to do, not what
you want them to do.  It is your job to make sure what you tell them to do
is what you want them to do.

In fact, we have already seen the example of adding two digits where the
computer was given the ascii codes to add, rather than the 2's complement
integers corresponding to those ascii codes.  If you give the computer ascii 
codes to add, the computer will treat those codes as integers, add them, 
producing garbage.

I think our instructions for the .bin file are pretty explicit.
The first line will contain the starting address, in this case x3000.  The
computer will put that address in the PC.  The rest of the lines contain
one instruction each which the computer will put into successive locations 
in the LC-3's memory, starting with the location whose address is in the PC.  
Then the computer will execute the program, starting with the instruction
that the PC points to.

That is the contract between the program and the computer.  Whether you 
write the program in machine language or you write it in JAVA and a JAVA
compiler translates it into the file that is presented to the computer,
the only way it can work is if both parties obey the same interface.

Finally, what about these vectors the student wants to put in memory.  
That one is easy.  Since TRAP x25 will halt the machine, the PC will never 
contain the address of the memory location after the location containing 
the TRAP x25 instruction.  So, just put the vectors there.  They will be 
in memory, readily accessible, but the PC will never get there so they will 
never be executed, and so will not produce garbage.

A picture (Suppose the TRAP x25 instruction is at location x3054):

...
x3054: 1111 0000 0010 0101
x3055: a vector to be used
x3056: another vector to be used
x3057: another vector to be used
x3058: another vector to be used
x3059: another vector to be used
...

OK?

Good luck.
Yale Patt