[Simh] Writeup of PDP-11 bootstrap loader analysis

Johnny Billquist bqt at softjar.se
Thu Dec 24 08:13:04 EST 2015



On 2015-12-24 02:02, Will Senn wrote:
>
>
> On 12/23/15 5:09 PM, Johnny Billquist wrote:
>>
>> As for your analysis:
>> Your explanation of branches seems somewhat over complicated. The
>> instruction is indeed in just 8 bits, while 8 bits are the offset.
>> However, there is no need to mess things up with one-complement, or
>> tricks like that. The offset is an 8-bit value. Sign extend to 16
>> bits. Multiply by 2, and add to the updated PC. Simple as that.
>> (Note that I said "updated PC". The PC will contain the address of the
>> instruction after the branch before you start doing the calculation
>> for the branch destination.)
>>
> Johnny,
>
> Given Line 7 037760  100376               BPL WAIT
>
> 100376 is a BPL instruction and the offset (376) is to be multiplied by
> two and added to the updated PC. That is, 376 * 2 is going to be added
> to 037762. 376 represents a negative offset in two's complement notation
> - it has a one in it's most significant bit, the left hand bit in 11 111
> 110. As a human, I kind of need the number in some form that makes sense
> to me, so I convert it to a positive quantity by first taking the one's
> complement and adding one. This gives me the positive magnitude of the
> negative number -1. Multiplying this by two is easy, it's -2, which when
> added to 037762 yields 037760 , which is the correct location. This is
> how I did the math. If I understand you correctly, the machine doesn't
> do it this way. I tried multiplying 376, 11 111 110 by shifting left
> one, 11 111 100, and adding that to 037762's binary representation, but
> that doesn't seem to make sense. Would you please elaborate?

Hmm, maybe your problem is that you don't fully know how to deal with 
twos complements, and sign extension. In reality, two's complement means 
you normally do not even care about this. It only matters for one step, 
and that is the sign extension. Sign extension means that you just copy 
the topmost bit for all the new bits you are adding when you are doing 
the sign extension. In this case, we are sign extending an 8-bit value 
to 16 bits.

To put this as the CPU does it...

11 111 110 is what you have in binary. Sign extend this gives:
1 111 111 111 111 110 (177776, or -2 in twos complement)

Now, multiply by two:
1 111 111 111 111 100 (177774, or -4 in twos complement)

PC is
0 011 111 111 110 010 (037762)

Add together:
1 111 111 111 111 100
0 011 111 111 110 010
---------------------
0 011 111 111 101 110

which reads out:
0  3   7   7   5   6

	Johnny

-- 
Johnny Billquist                  || "I'm on a bus
                                   ||  on a psychedelic trip
email: bqt at softjar.se             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol


More information about the Simh mailing list