Folkert van Heusden
Folkert van Heusden

Reputation: 534

PDP-11 assembler: how do "single operand instructions" work

I'm trying to understand PDP-11 assembly. For that I'm going through this document.

The PDP-11 has several sets of instruction-types. One being single operand instructions, an other is double operand instructions. A double operand instructions would be for example:

MOV   @(R0)+,R1

...which (if I understood it correctly) picks the data from the memory pointed to by R0, then increments R0 and then stores the data it got from memory into R1.

But what about single operand instructions? E.g.:

INC  @(R0)+

What will happen? Will it:

  1. retrieve the value pointed to by R0
  2. increase R0
  3. increase the value
  4. store the result into the new address pointed to by R0?
  5. increase R0 again?

or is 2 skipped or is 5 skipped?

Upvotes: 1

Views: 249

Answers (2)

MathWhiz
MathWhiz

Reputation: 21

It's been 35 years since I used my favorite PDP-11, but as I remember:

MOV @(R0)+,R1

Since MOV is a word instruction as opposed to byte, all increments/decrements are by 2 because they are word boundaries and must maintain word boundary integrity. For the instruction MOVB, the increment will be 1 for byte boundary, and byte boundary maintained.

@() is a double indirect so data is not where R0's value points to, but at the location pointed to by (R0). The increment, being after the source operand, makes it POST-increment so it bumps R0 by 2 after moving the data. The command

MOV -@(R0),R2 [ syntax may be @-() ]

pre-decrements by 2, then fetches the value from where the updated R0 points to, then uses that value as a pointer to where to get the data to move to R2.

It makes no difference in terms of understanding whether it is a single or double operand command because all the modes apply to each operand. The only exception being that you probably don't want to store data into the program, such as MOV R0,(PC)+ but you can do it... we used to save memory all the time like that, but usually it was from a source operand (see below).

Hope this helps even tho it's been a few years since asked.

--

We saved memory in the 64K-byte computers by embedding variable values in instructions and doing code such as the 2 lines below, in that exact order,

MOV @(PC)+,VAR ...... not sure of exact syntax

ABC: .WORD 0

..... not sure of that syntax any more to hold space for a word

which embeds the variable ABC in the operand of the MOV instruction... double-check me on that, but it's what I remember. It works because when MOV is decoded, PC already points to the next word where the offset value is, then fetches and bumps by 2 to the next instruction after completing.

Upvotes: 2

fuz
fuz

Reputation: 93062

This manual contains an example of INC -(R0) in §3.3.3 that clarifies that the increment/decrement happens once before/after the main operation of the instruction:

3.3.3 Autodecrement Mode

...

Autodecrement Mode Examples

  1. Symbolic: INC -(R0), Octal code: 005240, Instruction Name: Increment

    Operation: The contents of R0 are decremented by two and used as the address of the operand. The operand is increased by one.

  2. Symbolic: INCB -(R0), Octal code: 105240, Instruction Name: Increment

    Operation: The contents of R0 are decremented by one and used as the address of the operand. The operand is increased by one.

Upvotes: 3

Related Questions