MODULE addvectors; (*--------------------------------------------------------- File name: addvectors.pm Author: AG Date: 5/27/05 Problem: This program selects a portion of the chain, marked between LeftLimit and RightLimit. Then it adds N chains into LRes. Chains to be added are stored on an ARRAY of chains. LeftLimit = 3 RightLimit = 19 ArrLine[1] + ArrLine[2] +...= LRes ( from element 3 to element 19) Example of Execution 1: N: 5 LeftLimit: 3 RightLimit: 19 ArrLine[1]: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ArrLine[2]: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ArrLine[3]: 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ArrLine[4]: 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ArrLine[5]: 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 LRes: 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 Cycles: N additions. *) (*---------------------------------------------------------- CONFIGURATION ----------------------------------------------------------*) CONST MAXCELLS=1024; (* MAXCELLS cells in one line *) CONST N=5; CONFIGURATION chain[0..(MAXCELLS - 1)]; CONNECTION left: chain [i] -> chain[(i-1) MOD MAXCELLS]; right: chain[i] -> chain[(i+1) MOD MAXCELLS]; (*---------------------------------------------------------- VARIABLES ----------------------------------------------------------*) VAR LRes: chain OF INTEGER; i,LeftLimit, RightLimit: INTEGER; ArrLine: ARRAY[1..N] OF chain OF INTEGER; (*---------------------------------------------------------- MAIN ----------------------------------------------------------*) BEGIN (*define limits *) RightLimit:= 19; LeftLimit := 3; (*initialize array of lines *) FOR i := 1 TO N DO ArrLine[i] := i; END; (*FOR *) LRes := 0; IF LeftLimit < ID(chain) < RightLimit THEN (* select cells *) (*printing *) WriteString("N: "); WriteInt(N, 2); WriteLn; WriteString("LeftLimit: "); WriteInt(LeftLimit, 2); WriteLn; WriteString("RightLimit: "); WriteInt(RightLimit, 2); WriteLn; FOR i:= 1 TO N DO LRes := LRes + ArrLine[i]; (*add line *) (*printing *) WriteString("ArrLine["); WriteInt(i,0); WriteString("]: "); WriteInt(ArrLine[i], 2);WriteLn; END; (* FOR *) (*printing*) WriteString("LRes: "); WriteInt(LRes, 2); WriteLn; END; (* IF *) END addvectors.