PDP-11 problems

I strongly recommend against looking at the answers for the problems below until you have attempted the problems. (That's why I put the answers on separate web pages.) There is no need to print the answers out now; they'll be here when you come back, at least through the date of the final exam.


Problem #1

Here is a PDP-11 assembly language program.

.ORG 1000
MOV X, R2
MUL X, R2
TST R3
BNE OVERFLOW
MOV Y, R4
MUL Y, R4
TST R5
BNE OVERFLOW
SUB R4, R2
MOV R2, W
HALT
OVERFLOW:MOV #0, W
HALT
X:.WORD 22
Y:.WORD 33
W:.WORD 0

(a) Describe simply (in English) what it does (in general, for any values of X and Y).

(b) Assemble the program into unsigned 16-bit octal numbers. (Note that most addressing is relative.)

answer to problem #1


Problem #2

Here is a PDP-11 machine language program, in octal.

locvalue
2000016700
2002000034
2004030027
2006000001
2010001405
2012070027
2014000003
2016062700
2020000001
2022000402
2024071027
2026000002
2030020027
2032000001
2034003363
2036000000
2040000005

(a) Disassemble this program (convert it to assembly language). You needn't introduce labels.

(b) Describe simply what it does, and state the final contents of R0, R1, R7 (the PC), and memory location 2040, assuming that the PC starts at 002000.

Note: The bitwise AND of an integer with 1 discards all but its least significant bit. If this bit is zero, the number is even; else it is odd.

(c) Will the program work correctly if it is loaded at memory location 1000 instead of 2000? If yes, justify briefly; if no, explain why not.

answer to problem #2


Problem #3

Here is a PDP-11 assembly language program.

(a) Describe simply (in English) what it does.

(b) Assemble the program into unsigned 16-bit octal numbers. (Note that most addressing is relative.)

.ORG 2000
MOV #500, R1
MOV #600, R2
MOV #700, R3
MOV N, R4
JSR R7, ROUTINE
HALT
ROUTINE:MOV -(R1), R0
SUB (R2)+, R0
MOV R0, (R3)+
DEC R4
BGT ROUTINE
RTS R7
N:.WORD 40

answer to problem #3     DON'T LOOK AT MY ANSWER UNTIL YOU'VE TRIED IT YOURSELF!


Problem #4

Here is a PDP-11 machine language program, in octal.

locvalue
2000005000
2002005001
2004066701
2006000020
2010005200
2012020067
2014000010
2016002772
2020010167
2022000006
2024000000
2026000005
2030000006
2032000007

(a) Disassemble this program (convert it to assembly language). You needn't introduce labels.

(b) Describe simply what it does, and state the final contents of R0, R1, R7 (the PC), and memory locations 2026, 2030, and 2032, assuming an initial contents of [R7]=002000, [R0]=000055, [R1]=177002.

answer to problem #4


Problem #5

You are probably familiar with the formula the sum from i=0 to n of i is equal to (n**2 + n) over 2

Suppose that you were sceptical of this formula and no one showed you a proof. You try it for a few cases and it works, but you are having difficulty finding a proof yourself. Before looking harder for a proof you'd like to verify it for a few hundred cases or more, by computer.

Write a subroutine in PDP-11 assembly language which verifies this equation (i.e. that the two sides are indeed equal), for 0 <= n < N. It will be called as follows (or equivalent):

MOV #N, R0
JSR R7, ROUTINE
If overflow occurs at any point in your calculation, your subroutine should return with the overflow condition code set. Otherwise, if it finds a counterexample to this formula, it should return with the n counterexample in R0 and with carry set (and overflow clear). If it verifies the formula for all n, 0 <= n < N, it will return with carry and overflow both clear (and R0 can be anything).

Your program needn't be especially well-commented but you should explain your use of registers and anything else particularly unclear. Do not assemble your code; leave it in symbolic form.

answer to problem #5


Problem #6

Assemble the following code (it's relocatable, so just choose any address to assemble it at), then analyze its behaviour.
MOV #1, R0
ADD R0, (R7)+
ADD R0, (R7)+
ADD (R7)+, R0
ADD R0, (R7)+
NOP
HALT
Your answer should include an initial layout of memory, a final layout of memory, and final values of R0 and R7.

answer to problem #6


Problem #7

Here is a PDP-11 machine language program, in octal.

locvalue
160012700
162000030
164062717
166100000
170062700
172000020
174000000

(a) Disassemble this program (convert it to assembly language). You needn't introduce labels.

(b) Trace its execution and explain what happens. State the final contents of R0 and R7.

answer to problem #7


Problem #8

Write a subroutine in PDP-11 assembly language to compute the sum of an array of signed 16-bit numbers (normal PDP-11 words; i.e. you can use ADD). The calling sequence to add 20 words starting at location 3000 is:
MOV #3000, -(R6)
MOV #20, -(R6)
JSR R7, ROUTINE
ADD #4, R6
You return the computed sum in R0. Your subroutine may thus use R0 as a scratch register, but any other registers used must be pushed and restored.

Your subroutine is required to check for overflow. If none of the addition operations overflows, your subroutine must return the sum in R0, and with the V condition code clear. If any of the addition operations overflow, your subroutine must return with the V condition code set, and in that case it doesn't matter what the final contents of R0 is. In the case of overflow, the caller will ignore the returned contents of R0; thus your subroutine may return immediately. (So there would actually be a BVS instruction between the JSR and the ADD in the calling sequence above.)

You need not handle the case of zero-sized arrays; the count (second argument) must be positive. You are not required to handle any kind of incorrect use of your subroutine.

Your program needn't be especially well-commented but you should explain your use of registers and anything else particularly unclear.

Do not assemble your code; leave it in symbolic form.

answer to problem #8


Problem #9

(requires TRAP material)

You are assisting a group with a large body of code for older PDP-11s. These older PDP-11s did not have a DIV op, so they used an EMT. The group's programs contain the op 104112, which is to have the semantics R0 <- [R0] div M (integer quotient). The value M is contained in the following word of the program (as an immediate operand), which the EMT must skip upon return.

This group now has a newer PDP-11 which does have a DIV op. Their existing EMT will work, but it contains a software integer division routine which is not as fast as a DIV op. Your task is to write a new EMT routine which simply does the DIV. (They will be using a DIV directly in all new code, but they have a large body of existing code which they want to speed up, too.)

For simplicity, assume that there are no other EMT routines in operation, and that you needn't check that they used the correct opcode. If you get an EMT trap, it's this fake division op.

Your answer will have to set the trap vector as well as provide the code for the routine. Don't forget to save registers as appropriate; don't forget that the hardware DIV yields a two-word result (even though you don't care about the second word, it better not erase anything); and don't forget to skip the M value's word upon return.

answer to problem #9


[CSC 258 additional problems] [main course page]