PDP11/45 machine code question.

From: der Mouse <mouse_at_Rodents.Montreal.QC.CA>
Date: Sun Feb 20 19:48:45 2005

> I was looking at a listing for a light chaser for the PDP 11, and the
> last instruction is branch back 4, (BR -4). The hex for this is given
> as 000775

Octal, not hex, but yes.

> I understand that this is a bit type instruction, where the op code
> is the base code plus 2*offset. If the base code is 000400, how do I
> calculate the offset to make it go back ?

The low 8 bits of the instruction are a *signed* offset (measured in
words) from the point after the instruction to the target of the

> Is bit 7 a sign bit?

I think that's a yes, if by "bit 7" you mean the 000200 bit - but it's
two's-complement, not sign-magnitude, so just thinking of the 000200
bit as a sign bit without realizing that the 000177 bits are also
affected for negative offsets is misleading.

> full program is
> location contents opcode
> 001000 012700 mov #1,r0
> 001002 000001
> 001004 006100 rol r0
> 001006 000005 reset
> 001010 000775 br -4

Right. That branch instruction contains 0375 in the offset bits. This
is sign-extended and doubled (the latter to convert from a word offset
to a byte offset), giving 0177772, or -06, and then taken relative to
001012, the address after the branch. 001012-6 is 001004, which is
where execution picks up.

The reason I get -6 and the assembly code says -4 is that the -4 in the
code is relative to the beginning of the instruction, whereas the -6 is
relative to the byte just after the end of the instruction. The
assembler/disassembler deals with compensating for the difference.

/~\ The ASCII der Mouse
\ / Ribbon Campaign
 X Against HTML mouse_at_rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
Received on Sun Feb 20 2005 - 19:48:45 GMT

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:37:39 BST