[comp.lang.pascal] bit problem

am42+@andrew.cmu.edu (Alexander Paul Morris) (11/20/90)

It's really fast to move memory around, but what if you have to access
certain individual bits.  Is there any fast way to read/write a bit to
memory?  The application of this is for stuff like saving/retrieving
graphics windows from disk.  It goes very fast for the part of the
window that fits on a byte boundary, but anything over the bounday (not
a multiple of 8) has a for-do kind of setup that reads a bit, etc, etc. 
But that slows it down A LOT.  It takes longer to manipulate several
rows of bits in a window (not on a boundary) than it takes to save the
whole screen (using a blockwrite or mem move).

    Alexander Morris                  "People die, things change...
    Carnegie Mellon                             It's sad."

zhou@brazil.psych.purdue.edu (Albert Zhou) (11/20/90)

I don't know what kind of Pascal you are talking about. In general, if you
could make "AND" operation on your version of Pascal, you might easily 
access individual bit. For example if you want to access the third bit of
a byte-size variable x, you could do it by evaluating:
             x AND 00000100

37KGLLQ@CMUVM.BITNET (Tony Papadimitriou) (11/20/90)

am42+@andrew.cmu.edu (Alexander Paul Morris) writes:

>It's really fast to move memory around, but what if you have to access
>certain individual bits.  Is there any fast way to read/write a bit to
>memory?  The application of this is for stuff like saving/retrieving
>graphics windows from disk.

There is fast bit insertion/exctraction sample code in the 386SX Programmer's
reference manual (pp. 3-18 .. 3-22).

It uses the 386-specific double-shift instructions.

I am not aware of faster-than-usual way to do this on a 8086 or 286.

------------------------------------------------------------
Tony Papadimitriou, Computer Science Department, C.M.U.
E-Mail: 37KGLLQ@CMUVM.BITNET