Modula-2

toc
 * Home * Programming * Languages * Modula-2**


 * Modula-2** is a general purpose [|procedural programming] language, designed and developed between 1977 and 1980 by [|Niklaus Wirth] at ETH Zurich, as successor to his earlier programming language Pascal and influenced by the [|Mesa programming language]. Modula-2 was sufficiently flexible to do [|system programming]. [|Object oriented] Modula-2 was co-developed by Elmar Henne.

=Sample Code= A [|CRC-32] implementation in Modula-2 by Alexander Naumov : code format="pascal" IMPLEMENTATION MODULE CRC32;

FROM SYSTEM IMPORT CARD8, CARD32, SET8, SET32, CAST, LOC, ADDRESS, SHIFT, ADR, ADDADR;

CONST crcPoly = 0EDB88320H;

VAR Table: ARRAY [0..255] OF SET32;

PROCEDURE Init (VAR crc: CARD32); BEGIN crc := 0FFFFFFFFH; END Init;

PROCEDURE Get (crc: CARD32): CARD32; BEGIN RETURN CAST(CARD32, {0..31}-CAST(SET32, crc)); END Get;

PROCEDURE Update (VAR crc: CARD32; buf: ARRAY OF LOC); BEGIN RawUpdate(crc, ADR(buf), HIGH(buf)+1); END Update;

PROCEDURE RawUpdate (VAR crc: CARD32; buf: ADDRESS; len: CARDINAL); VAR c: SET32; BEGIN c := CAST(SET32, crc); WHILE len > 0 DO   c := Table[CAST(CARD8, CAST(SET8, c) / CAST(SET8, buf^))] / SHIFT(c, -8); buf := ADDADR(buf, SIZE(SET8)); DEC(len, SIZE(SET8)); END (*WHILE*); crc := CAST(CARD32, c); END RawUpdate;

PROCEDURE InitTable ; VAR i, j: CARDINAL; c  : SET32; BEGIN FOR i := 0 TO 255 DO   c := CAST(SET32, i); j := 8; REPEAT IF 0 IN c THEN c := SHIFT(c, -1) / CAST(SET32, VAL(CARD32, crcPoly)); ELSE c := SHIFT(c, -1); END (*IF*); DEC(j); UNTIL j = 0; Table[i] := c; END (*FOR*); END InitTable;

BEGIN InitTable; END CRC32. code

=External Links=
 * [|Modula-2 from Wikipedia]
 * [|Modula-2 home]
 * [|Modula-2+ from Wikipedia]
 * [|Free Modula-2 Pages: Home]
 * [|comp.lang.modula2]

=References= =What links here?= include page="Modula-2" component="backlinks" limit="40"
 * Up one Level**