Re: Does anybody have any experience using SCANWC in MI? Looking to find the first character *not* matching a specific value.
"James H. H. Lampert via C400-L" <[email protected]> Thu, 12 Oct 2023 15:01:04 -0700
| Newsgroups | gmane.comp.lang.as400.c |
|---|---|
| Message-ID | <[email protected]> |
Empiricism has its advantages.
DCL DD FOO CHAR(20) AUTO INIT('00000000001234567890');
DCL SPCPTR BAR AUTO;
DCL SPCPTR BAZ AUTO INIT(FOO);
DCL DD FIRSTNZ BIN(4) AUTO;
DCL DD CONTROL CHAR(8) AUTO INIT(X'010000F000000014');
ENTRY .ENTRY EXT;
SETSPPFP BAR, BAZ;
SCANWC BAR, CONTROL, X'06000000', =+1;
: SUBSPPFO FIRSTNZ, BAR, BAZ;
ADDN(S) FIRSTNZ, 1;
RTX *;
PEND;
FOO is the string to be searched. BAR is the pointer we're going to be
feeding to the SCANWC statement. BAZ is a pointer used to initialize
BAR, and then subtract from BAR in order to get the character position.
FIRSTNZ is where we're going to put the difference.
CONTROL is the 8-byte control word:
01: Base and comparison mode both simple, starting the scan.
00: Reserved
00F0: looking for an EBCDIC '0'
00: Reserved
000014: Base length is 20
First, we SETSPPFP to initialize BAR from BAZ.
Then, we SCANWC our string, with the control, and option word as follows:
06: Option indicators, match if greater or less
000000: Reserved.
The fourth operand is where to go if it finds something that's less than
an EBCDIC space; supposedly, it will accept a Null or omitted operand,
but I couldn't figure out how. Note that it's essentially a naked branch
target; in this case, a naked relative branch target just going to the
next instruction.
At the end of the SCANWC, the offset in BAR has been set to the offset
of the first character that isn't an EBCDIC zero.
Next, we subtract BAZ from BAR, to get the character position, and add
1, so that we're working with character positions (starting with 1)
rather than offsets (starting with 0).
If you then run this in the debugger, with a breakpoint on the RTX,
you'll get the expected result.
--
JHHL
--
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/c400-l
or email: [email protected]
Before posting, please take a moment to review the archives
at https://archive.midrange.com/c400-l.