MODULE insert; (*--------------------------------------------------------- File name: insert.pm Author: MM, AG Date: 6/09/05 Problem: Insert (add) a scalar in the first selected cell of the chain. Comment: This is a simulation of the insert function, which exists in the assembly language of the Connex Machine. However, to our knowledge, Parallaxis does not offer such a function. The purpose of this simulation is to be able to write other functions that depend on insert. Example of Execution (INSERT 7 IN FRONT OF FIRST 4) Initial Line: 0 1 2 1 0 4 0 1 4 0 0 4 1 2 0 Result: 0 1 2 1 0 7 4 0 1 4 0 0 4 1 2 Cycles (function): PARALLAXIS 1 assign + 2 test + 1 shift + 1 REDUCE + 1 ID. Cycles (Connex): 1 *) (*---------------------------------------------------------- CONFIGURATION ----------------------------------------------------------*) CONST MAXCELLS=1024; (* MAXCELLS cells in one line *) CONFIGURATION chain[0..(MAXCELLS - 1)]; CONNECTION left: chain [i] -> chain[(i-1) MOD MAXCELLS]; right: chain[i] -> chain[(i+1) MOD MAXCELLS]; (*---------------------------------------------------------- VARIABLES ----------------------------------------------------------*) VAR L0ID, L1Res: chain OF INTEGER; w, ind:INTEGER; (*---------------------------------------------------------- MAIN ----------------------------------------------------------*) BEGIN (* initialize data *) L1Res:= RandomInt(chain) MOD 5; w:= 7; (* insert w *) (* Printing *) IF ID(chain) < 16 THEN WriteString("Initial Line: "); WriteInt(L1Res, 2); WriteLn; END; (* display *) (* prepare selectin *) L0ID:= ID(chain); (* find position for first 4 *) IF L1Res = 4 THEN ind := REDUCE.FIRST(L0ID); (* INDEX OF FiRST SELECTED *) END; (* IF *) (* insert w before the first 4 *) IF L0ID > ind THEN L1Res := RECEIVE.right(L1Res); L1Res<>:= w; END; (* IF *) (* Printing *) IF ID(chain) < 16 THEN WriteString("Result: "); WriteInt(L1Res, 2); WriteLn; END; (* display *) END insert.