Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

A PDP-11 program

p_vp_v Member Posts: 61
Hello,

I am presenting here a pascal program for matrix multiplication and the corresponding PDP-11 program from the book "Computer Organization" by Carl Hamacher. I have some doubts which I would request the list to look into. I have appended these questions at the end.

Pascal program

for i:= 0 to n-1 do
begin
for j:= 0 to n-1 do
begin
C(i,j)= 0;
for k:= 0 to n-1 do
C(i,j):= C(i,j) + A(i,k) x B(i,k)
end
end

PDP-11 program

CLR RO
LOOPI: CLR R2

LOOPJ: MOV R2,R1
MUL N,R1
ADD R0,R1
ASL R1
CLR C(R1)
CLR R4

LOOPK: MOV R4,R3
MUL N,R3
ADD R0,R3
ASL R3
MOV A(R3),R3
MOV R2,R5
MUL N,R5
ADD R4,R5
ASL R5
MUL B(R5),R3
ADD R3,C(R1)
INC R4
CMP R4,N
BLT LOOPK
INC R2
CMP R2,N
BLT LOOPJ
INC R0
CMP R0,N
BLT LOOPI

Here, R0, R2 and R4 hold the values i, j and k respectively. N is the memory location holding the value n. Array subscripts run from (0,0) to (n-1,n-1). The elements of each array are stored in consecutive word locations beginning with (0,0) and continuing in column order. All the elements are 16-bit integers.

My question is: In the book, the formula for calculating the byte address of element(i,j) of an array, relative to the address of the first element, is given as 2(nxj+i). Could anyone provide an explanation?.

Secondly, how is it that the addressable space of a PDP-11 is 2-to-the-power-of-15 words or 2-to-the-power-of-16 bytes? Since each word consists of 16 bits, it should have been 2-to-the-power-of-16 words.

thanks and regards
PV










Comments

  • korkor Member Posts: 198
    Not sure about question 2, but question one is fairly simple:
    Memory is linear, one dimensional, that array is not. To simulate a second dimension, each j value is an offset, and the i values remain constant. That j value then must be equal to (max i)*j, forcing the element location in memory relative to the first element in the array to be (max i)*j+i. This is the most effecient use of memory for something like this, but causes problems resizing the max i value of the array.

    Also, you don't need 10 extra blank lines at the bottom of the post...

    : Hello,
    :
    : I am presenting here a pascal program for matrix multiplication and the corresponding PDP-11 program from the book "Computer Organization" by Carl Hamacher. I have some doubts which I would request the list to look into. I have appended these questions at the end.
    :
    : Pascal program
    :
    : for i:= 0 to n-1 do
    : begin
    : for j:= 0 to n-1 do
    : begin
    : C(i,j)= 0;
    : for k:= 0 to n-1 do
    : C(i,j):= C(i,j) + A(i,k) x B(i,k)
    : end
    : end
    :
    : PDP-11 program
    :
    : CLR RO
    : LOOPI: CLR R2
    :
    : LOOPJ: MOV R2,R1
    : MUL N,R1
    : ADD R0,R1
    : ASL R1
    : CLR C(R1)
    : CLR R4
    :
    : LOOPK: MOV R4,R3
    : MUL N,R3
    : ADD R0,R3
    : ASL R3
    : MOV A(R3),R3
    : MOV R2,R5
    : MUL N,R5
    : ADD R4,R5
    : ASL R5
    : MUL B(R5),R3
    : ADD R3,C(R1)
    : INC R4
    : CMP R4,N
    : BLT LOOPK
    : INC R2
    : CMP R2,N
    : BLT LOOPJ
    : INC R0
    : CMP R0,N
    : BLT LOOPI
    :
    : Here, R0, R2 and R4 hold the values i, j and k respectively. N is the memory location holding the value n. Array subscripts run from (0,0) to (n-1,n-1). The elements of each array are stored in consecutive word locations beginning with (0,0) and continuing in column order. All the elements are 16-bit integers.
    :
    : My question is: In the book, the formula for calculating the byte address of element(i,j) of an array, relative to the address of the first element, is given as 2(nxj+i). Could anyone provide an explanation?.
    :
    : Secondly, how is it that the addressable space of a PDP-11 is 2-to-the-power-of-15 words or 2-to-the-power-of-16 bytes? Since each word consists of 16 bits, it should have been 2-to-the-power-of-16 words.
    :
    : thanks and regards
    : PV


Sign In or Register to comment.