🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.modula2
3 messages
3 total messages Started by Ken Yap Thu, 27 Aug 1987 19:36
Re: Bit-shifting Operations
#3787
Author: Ken Yap
Date: Thu, 27 Aug 1987 19:36
18 lines
1287 bytes
>Organization: U of Rochester, CS Dept, Rochester, NY

In article <632@jimi.cs.unlv.edu> zimmerle@jimi.cs.unlv.edu (Robert Zimmerle) w
rites:
|Turbo Pascal and "C" have native bit-shifting operations, but not
|Modula-2.  Was this omission a wise design decision?  I would like
|to read some opinions on this question.

Yes, but if you're going to compare, Turbo Pascal is not standard
Pascal.

A good question though is: what do people use bit shifting for in
C and how would one write the equivalent in M-2? I know I use bit
shifting to (1) make bitmasks, which M-2 can do with BITSETs and
(2) (not so much now) multiply and divide, which shouldn't be
a BITSET operation anyhow. So what can BITSETs not do?

          Ken
Re: Bit-shifting Operations
#3804
Author: Steve Smith
Date: Thu, 03 Sep 1987 22:16
32 lines
2520 bytes
In article <8708271750.AA03034@cayuga.cs.rochester.edu> ken@CS.ROCHESTER.EDU (Ken Yap) writes:

>A good question though is: what do people use bit shifting for in
>C and how would one write the equivalent in M-2? I know I use bit
>shifting to (1) make bitmasks, which M-2 can do with BITSETs and
>(2) (not so much now) multiply and divide, which shouldn't be
>a BITSET operation anyhow. So what can BITSETs not do?

The main use that I've found for bit twiddling, shifting, etc. is a
devilish contraption known as a device regester.  This refers especially
to UARTs, DMA chips, etc, although CPU status regesters have the same
problems.  For their own good (:-) reasons, hardware designers tend to
put the fields you're interested in someplace other than the beginning
of a word.  For single bit values, this is no problem - bitsets are just
great.  However, for multibit numeric values, this gets grubby.  In
assembly language, you just mask off the part you're interested in and
shift it over into the least significant position, where your compare
instructions can handle it sensibly.  In Pascal, you declare your
register as a PACKED RECORD of however you want things handled.  This
should compile into a mask-and-shift just like the assembly version.
(I'm an optomist :-)

I really don't see a clean way of doing a mask, shift, and compare in
M2.  The mask is done easily enough with a bitset, but then how do you
do a sensible compare?  How do you tell that (say) {10, 12} > {10, 11}
without doing a type transfer onto a CARDINAL?  Note that a program full
of type transfers is prime ammunition for the anti-strong typing crowd.
-- 
                           __
 -- Steve          /      /  \      /         "Truth is stranger than
S. G. Smith      I \ O    |  _    O \ I        fiction because fiction
smith@cos.com      /      \__/      /          has to make sense."
Re: Bit-shifting Operations
#3806
Author: Randy Bush
Date: Fri, 04 Sep 1987 20:21
13 lines
1248 bytes
smith@cos.UUCP (Steve Smith) writes:
>The main use that I've found for bit twiddling, shifting, etc. is a
>devilish contraption known as a device regester.  This refers especially
>to UARTs, DMA chips, etc, although CPU status regesters have the same
>problems...

As Modula-2 is purported to be a SIL which provices for all aspects of
programming a machine, one would expect reasonable implementations to
allow one to describe a device register as a record and not have to
mash on the bits by hand.
-- 
Randy Bush, Compiler Group, Oregon Software, Portland Oregon (503) 245-2202
uucp: ..!tektronix!oresoft!randy       Telemail: RBush     Fidonet: 1:105/6
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads