From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,2ffa52accff67cd1 X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 1994-10-02 04:27:40 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!swiss.ans.net!solaris.cc.vt.edu!news.duke.edu!godot.cc.duq.edu!newsfeed.pitt.edu!vms.cis.pitt.edu!bschor From: bschor@vms.cis.pitt.edu Newsgroups: comp.sys.dec Subject: Re: bitwise in VAXELN Pascal Date: 2 Oct 94 07:26:51 EST Organization: University of Pittsburgh Message-ID: <36m5du$9gb@usenet.srv.cis.pitt.edu> References: <33vjg7$u3@news.bu.edu> <365p6h$ngg@newsbf01.news.aol.com> NNTP-Posting-Host: axpvm1.cis.pitt.edu 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