broman@noscvax.UUCP (Vincent P. Broman) (08/20/85)
<> The explanation of WORD and ADDRESS in Wirth's "Programming in Modula-2" has produced fog and confusion in me. I wonder whether someone who has worked with an Actual Implementation (I haven't) could shine a light. Wirth implies repeatedly that contiguous WORDs have consecutive ADDRESSes, for instance in his code on p127 he increments an ADDRESS by 1 to access the next WORD. Since many machines are byte-addressed, this seems to imply that these would also have WORD=byte. On the other hand, the impression is given that a WORD is the natural access unit of the machine, and says on p126 "On the PDP-11, TSIZE(WORD)=2, since the addressable unit of store is the byte" (even though TSIZE really counts WORDs). Should a VAX get 4-byte WORDs? Also, if ADDRESSes are usable as CARDINALs for arithmetic, is this hard to do on the 8088 family, with 16-bit integers and 20-bit addresses? I suppose the Turbo Modula coming out now will only implement a small memory model, avoiding the problem, but do Logitech and the others implement it with long CARDINALs? UUCP: ucbvax!sdcsvax!noscvax!broman Vincent Broman ARPA: broman@nosc Naval Ocean Systems Center, code 632 Phone: (619) 225-2365 San Diego, CA 92152
bobc@tikal.UUCP (Bob Campbell) (08/23/85)
*** BUG FOOD *** The general discription on pages 126, and 127 leaves much to be desired it appears however to be written with machines who's smallest addressable unit of memory is a "WORD" in mind. Many of the documents I have seen from ETHZ make comments about using CYBER computers, which I believe have a "WORD" (other than 16 or 32 bits) addressed as the smallest unit of memory. When running on a CYBER computer I believe the example on page 127 is valid. The note "On the PDP-11, TSIZE(WORD) = 2,..." implies that sizes are measured in the size of the Smallest Addressable unit. It would appear that a VAX should have 4-byte WORDS, however would this make LONGINT an 8-byte value? The ETHZ implementation of Modula-2 for the 68000 has CHAR = 1 Byte WORD = 2 Bytes INTEGER = 2 Bytes ADDRESS = 4 Bytes The is a note with the compiler that 'ADDRESS may be used in the sense of a "long cardinal (32 bit)".' It would therefore seem that the example on page 127 should be as follows to be correct for all machines: ReadWord(in,length); length := length -1;a := ADR(buffer); WHILE length > 0 DO ReadWord(in,a^); a := a + TSIZE(WORD); length := length - 1 END Bob Campbell uw-beaver!tikal!bobc
peter@graffiti.UUCP (Peter da Silva) (08/31/85)
> The note "On the PDP-11, TSIZE(WORD) = 2,..." implies that sizes are measured > in the size of the Smallest Addressable unit. It would appear that a VAX > should have 4-byte WORDS, however would this make LONGINT an 8-byte value? Sunds like a step backwards to me. 'C' handles all the word/byte/long/etc arithmetic for you... and Modula 2 is supposed to be higher level than that. I hope they fix this pronto.
bobc@tikal.UUCP (Bob Campbell) (09/03/85)
In article <138@graffiti.UUCP> peter@graffiti.UUCP (Peter da Silva) writes: >Sunds like a step backwards to me. 'C' handles all the word/byte/long/etc >arithmetic for you... and Modula 2 is supposed to be higher level than that. Does it really? it would seem to me that both 'C' and Modula-2 act the same with regard to the functioning of sizeof, TSIZE, and SIZE. They all return the size in the machines "smallest addressable unit" (a byte for machines which support them, and other odd things for other machines). A word is composted at least of one of the smallest addressable units and is the machines native data size. For pdp11's it is 16 bits or 2 bytes TSIZE(WORD) = 2 sizeof(int) = 2. For vaxes it is 32 bits or 4 bytes TSIZE(WORD) = 4 sizeof(int) = 4. (the 68000 is in question as it it not clear if it is best used as a 32 bit machine or a 16 bit machine but since the processor calls 16 bits a word and 32 bits a long it would best be implemented that way.) As for pointer arithmetic C treats address calulations as array indexing operations, this is a neat feature in a few cases, but this is not one of the high level features of C but instead is one of it's low level features. One which is used much too offen, and degrades the maintainability of C code. A good object code improver (some times called a optimizer incorrectly) would remove the most common advantages of using pointer arithmetic. ADDRESS arithmetic is not supported as a high level feature of Modula-2 it is instead supported as a low level feature, as the language accepts the fact that some programs require low level support. > I hope they fix this pronto. If it isn't broke don't fix it. Bob Campbell uw-beaver!tikal!bobc