From: bschor@vms.cis.pitt.edu
Subject: Re: bitwise in VAXELN Pascal
Date: 2 Oct 94 07:26:51 EST [thread overview]
Message-ID: <36m5du$9gb@usenet.srv.cis.pitt.edu> (raw)
In-Reply-To: 365p6h$ngg@newsbf01.news.aol.com
In article <365p6h$ngg@newsbf01.news.aol.com>, politzer@aol.com (Politzer) writes:
> In article <33vjg7$u3@news.bu.edu>, kearns@buphy.bu.edu (Ed Kearns)
> writes:
>
> ELN Pascal has a [bit] type. You can declare a packed array [x..y] of
> [bit] and then do any standard array operations on it. I have
> successfully used this
> technique on VME bus cards that present bit masks in status registers. It
> was more straight forward than treating them as unsigned integers.
>
> Hope this helps,
> Bruce
> Politzer@aol.com
>
I didn't see the original post, but if you are trying to do bit
manipulations in Pascal, there is a very easy (and 100% "legal") way to do
it, taking advantage of the SET type.
Suppose you have a 16-bit register, with the bits defined as follows:
Bit 0 Go
Bit 6 Interrupt Enable
Bit 7 Ready flag
Bit 15 Error flag
Use a 16-element enumerated type to name the bits, and make a set out of
them.
TYPE
registerbittype = (go, bit1, bit2, bit3, bit4, bit5, intenable,
readyflag, bit8, bit9, bit10, bit11, bit12, bit13,
bit14, errorflag);
registerset = SET OF registerbittype;
Most Pascal implementations (and you need to check on this!) will implement
the registerset defined above as a two-byte "array of bits", just what you
want. You manipulate the bits by simple set operations.
VAR
deviceregister : registerset;
PROCEDURE cleardevice
BEGIN { cleardevice }
deviceregister := []
END;
PROCEDURE enableinterrupt;
BEGIN { enableinterrupt }
deviceregister := deviceregister + [intenable]
END;
PROCEDURE disableinterrupt;
BEGIN { disableinterrupt }
deviceregister := deviceregister - [intenable]
END;
FUNCTION oopserror : boolean;
BEGIN { oopserror }
oopserror := errorflag IN deviceregister
END;
Note that I'm assuming that you have some way of defining "deviceregister"
to be either the hardware register itself or an appropriate copy of it.
I've successfully used this technique on both the PC and PDP-11s. I find
the use of Pascal sets to represent bits this way quite intuitive and easy
to understand. Note that all of the "thinking" goes into the definition of
the enumerated type -- that's the only place that actual knowledge of the
hardware is needed (to define the bit locations).
Bob Schor
Pascal/PDP-11 enthusiast
prev parent reply other threads:[~1994-10-02 12:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1994-08-30 15:33 bitwise in VAXELN Pascal Ed Kearns
1994-08-31 12:19 ` Peter Hermann
1994-09-26 6:20 ` Politzer
1994-10-02 12:26 ` bschor [this message]
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox