My only assembler joke is this,

Newbie: What’s the difference between L and LA?

Old Hand: About a week of debugging.

I earned the right to use that joke (over and over by the way) because it happened to me. Ever since then, I pay special attention whenever I code L or LA. The same might be said of Load Complement Register (LCR) and Load Negative Register (LNR).

If we code LCR, what are we expecting? In this context, “complement” really means “additive complement”. We say that X is the additive complement of Y if X + Y = 0. We also note that if X is the complement of Y, Y is also the complement of X. So, the complement of 7 is -7, the complement of -3 is 3, and the complement of 0 is 0.

There is one complicating factor concerning any two’s complement representation we choose: There is always one more negative integer than there are positive integers. For example, in 3-bit two’s complement, the range of numbers is -4, -3, -2, -1, 0, 1, 2, 3. There are four negative integers but only three positive integers because zero has a positive sign. If we ask for the complement of -4, the answer is 4 which can’t be represented with three bits. An overflow will occur. There are two integers which remain the same when complemented: the maximum negative integer and 0. If we complement the maximum negative integer, it remains unchanged and an overflow is signaled. In fact, this is the only way to get an overflow with LCR.

Here are the condition codes you can get with LCR.

Code Meaning

0 Result zero, no overflow

1 Result less than zero, no overflow

2 Result greater than zero, no overflow

3 Overflow

What about Load Negative Register (LNR) and for that matter, Load Positive Register (LPR)? Perhaps the way to keep all three instructions straight is to remember that **“You get what you ask for.” **If you code LNR, the result will be negative. If you code LPR, the result will be positive. If you code LCR, you will get the additive complement which can be positive or negative.

So, what does LNR do? If the integer in operand 2 is negative, it is placed into operand 1 unchanged. If the integer in operand 2 is positive, it is complemented and placed in operand 1. We will always produce a negative result with LNR. Since all positive integers have complements, no overflow can occur. Here are the condition codes for LNR.

Code Meaning

0 Result zero

1 Result less than zero

2 —

3 —

What does LPR do? If the integer in operand 2 is positive, it is placed in operand 1. If the integer in operand 2 is negative, it is complemented and placed in operand 1. We will always produce a positive result (except for the maximum negative integer). If you complement the maximum negative integer, an overflow occurs. Here are the condition codes for LPR.

Code Meaning

0 Result zero, no overflow

—

2 Result greater than zero, no overflow

3 Overflow

The moral to this tale is *you get what you ask for*. LPR produces positive results. LNR produces negative results. LCR produces complements which are sometimes positive and sometimes negative.

Now you can spend that week doing something really productive.