Perform a logical bit-wise operation on two bit patterns in memory.
MemAnd [(] src_addr,dst_addr,count [)]
MemOr [(] scr_addr, dst_addr, count [)]
MemXor [(] scr_addr, dst_addr, count [)]
scr_addr,dst_addr | : address |
count | : integer expression |
Each command performs a different logical bit-wise operation on two bit patterns in memory:
In all cases, scr_addr specifies the address of the source, dst_addr the address of the destination location, and count specifies the number of bytes to use at both locations. The logical And results in the target bits being set only when the corresponding bits are set in both source and target area.
OpenW 1
Win_1.FontTransparent = True // Needed to print properly on Win8/10
Local a%
Global a?(15), b?(15)
a?(9) = -1, b?(9) = -1, b?(10) = -1, b?(12) = -1 // Set initial flags
test("Before any operations:")
MemAnd V:a?(0), V:b?(0), (Dim?(a?()) + 7) >> 3 // Only b?(9) remains set
test("After MemAnd:")
b?(9) = -1, b?(10) = -1, b?(12) = -1 // Reset flags for MemOr
MemOr V:a?(0), V:b?(0), (Dim?(a?()) + 7) >> 3 // b?(9), b?(10) and b?(12) remain set
@test("After MemOr:")
b?(9) = -1, b?(10) = -1, b?(12) = -1 // Reset flags for MemXor
MemXor V:a?(0), V:b?(0), (Dim?(a?()) + 7) >> 3 // b?(9) is reset
@test("After MemXor:")
Procedure test(txt$)
Local i%
Print txt$
Print "a?() - ";
For i% = 0 To 15 : Print Str$(a?(i%), 2, 0)` : Next : Print
Print "b?() - ";
For i% = 0 To 15 : Print Str$(b?(i%), 2, 0)` : Next : Print
EndProc
This method of memory manipulation can be particularly handy for use with databases. For example, if a database contains variables which are used as flags to mark (-1) or not to mark (0) an attribute, these method of memory manipulation can be very helpful. Using MemAnd an inquiry can be made to see if the markers apply to one or both attributes, with MemOr to see if the markers apply to either one or both attributes, while with MemXor an inquiry can be made to see if the markers apply to one or the other but not both attributes..
{Created by Sjouke Hamstra; Last updated: 04/03/2017 by James Gaite}