A student writes:


     I finished my program but i kept on getting this
     one error "instruction
     reference label "(name of label)" that cannot
     be represented in a 9 bit signed
     PC Offset" when i assembled.  My program
     turned out to be 796 lines (probably
     too big) but I am fairly certain that it
     works after reading over it a few
     times.  Is there anything I can do about this
     or do i have to redo my program
     to fit so that I can assemble it?

     << name withheld to protect one who does not sign his email >>

A few things seem relevant to point out:

First, his statement: "I am fairly certain that it works after reading over it a few times." Riddle: What do we call a program whose author has just made the above statement? Answer: A program that does not work.

The software industry wastes billions of dollars a year (billions, I am told) because of bugs in programs whose authors "read them over a few times" and convince themselves their programs work. Does that mean you should not go over your program by hand? Of course not. Should you trace your program by hand? Sure. [And, you do know what "trace" means, right?]

BUT that is not enough. That is why we have a Simulator and why we urge you to test your program on the Simulator by stepping through it, inserting values, testing results of instruction execution, using breakpoints where useful, etc. Testing should involve as best as you can the "corner cases," that is, the data values where your program could screw up even though on nice values, everything is fine. For example, testing whether three lengths form a triangle. If the sum of the smaller two are larger than the largest, voila! A triangle. How about the sides 2,2,4 or 0,4,4. Ooops! The operative word in the test was "larger" and 4 is not larger than 4.

Anyway, I digress. Back to the student's question.

Second, 796 lines. Wow! That is long. He says "probably too big." Yeah, I guess so. We will not criticize a program that is too long in 306, but you will have to use instructions that "work" in that situation. You have 15 opcodes. Some don't care about where the data is, others do. You need to use those instructions that take all of this into account.

Third, "Do I have to redo my program to fit so I can assemble it?" No. You have two choices. (1) Use instructions appropriate to the situation you are in. Look at the instruction presenting the problem. Ask yourself: why is it presenting a problem? Is there any way to get around the problem? ...and act accordingly. Or, (2) Ask yourself, is there an easier way to do the whole job that does not take 796 lines. ...and act accordingly.

Good luck.

Yale Patt