• Keine Ergebnisse gefunden

String Editing30

Im Dokument UPDATE NOTICE (Seite 164-172)

User Operations

2.14 String Editing30

The edit instruction implements more complex operations on strings than merely moving or translating, and before investigating it the reader should be familiar with the general characteristics of strings (and cautions about them) as presented at the beginning of 42.12. Edit provides the facilities needed, particularly in COBOL and PL/I, to create formatted character strings for output. Typical features are the ability to suppress leading zeros, insert special symbols such as decimal points or currency symbols, and recognize different types of numbers for operations like adding “CR” or

“DB” after them. When numbers appear in running text, leading zeros are usually deleted; when they are lined up in columns (such as in a financial statement), the practice is to substitute spaces.

Edit uses the usual source and destination byte pointers, but no string lengths are given. Instead the source bytes are processed by commands in a pattern command string, whose structure is determined by the expected length of the source. The pattern commands are g-bit bytes packed four to a word. They are executed according to a pattern pointer, which supplies the address of a memory location and a 2-bit byte number, wherein the numbers O-3 identify the bytes from left to right in the word. The destina- tion string space is assumed to be large enough for whatever string edit creates.

Available to the procedure are a translation -table at El like that of MOVST, and a message insertion table following EO. EO + 1 contains the fill character - typically a space - for suppression of leading zeros; but if the whole word containing the fill character is zero, the fill is not inserted in the destination space, thus deleting leading zeros. EO + 2 contains a float character - typically a currency symbol or plus sign - which, if the word containing it is nonzero, is inserted before the first significant byte. The table can extend to EO + 100, thus supplying an additional sixty-two char- acters for insertion in the string being generated. Insert characters are typically decimal point, comma, “C” and “R”, and so forth.

For signaling significance AC has an S bit, which can be set from the translation table when significance starts. At this point the destination string position is marked by storing the current value of the destination pointer at a location specified by a mark address. This provides a record of where significance started, so the instruction can go back to make revisions if need be after receiving more information from the source.

EDIT is a two-word instruction, where the first has the EXTEND code 123, and it uses a block of six accumulators. The description is accompanied by a flowchart.

2-104 User Operations

EDIT Edit String

Definitions: Initially the pattern pointer, which comprises the pattern string address and byte number, points to the first pattern command. Pat- destination byte pointer is incremented first.

Execute the pattern command specified by the pattern pointer. At the

SELECT I 001 Select Next Source Byte

0 8

Read the next byte from the source string, and carry out the corresponding translation function given in the appropriate half word at location El + B/2 in the translation table, where B is the value of the source byte.

Each word in the table has this format.

TRANSLATION FUNCTION FOR EVEN B TRANSLATION FUNCTION FOR ODD B

C%E 0 SUBSTITUTE FOR BYTE SUBSTITUTE FOR BYTE

(MAXIMUM 12 BITS) C%E 0 (MAXIMUM 12 BITS) Location El + B/2

0 2 6 17 18 20 24 35

Perform the function specified by the op code in the half word correspond- ing to the source byte as follows.

If S is 1 place the substitute in the next position in the destination string space. Otherwise if location EO + 1 is nonzero, place the fill character from it in the next destination position.

Increment the pattern pointer, and go on to the next instruction.

Clear it4 and then perform function 0.

Set M and then perform function 0.

Set N. If S is 1 place the substitute in the next position in the desti- nation string space. Otherwise do the following: set S; put the cur- rent value of the destination byte pointer at the location specified by the mark address; if location EO + 2 is nonzero, put the float charac- ter from it in the next destination position; then place the substitute in the next destination position after that.

Set N, increment the pattern pointer, and go on to the next instruc- tion.

Clear M and then perform function 4.

Set M and then perform function 4.

Notes. The translation table starts at location El, and since there are two functions per word, it contains 2”’ locations, where n is the number of bits in a byte. The address is generated by adding the left n - 1 bits of a byte to El.

SIGST I 002 Start Significance

0 8

If S is 0 do the following: set S; put the current value of the destination pointer at the location specified by the mark address; and if location EO + 2 is nonzero, put the float character from it in the next destination position.

Notes. A typical use of this command might be before a final character to guarantee that zero is represented by one “0.” Or if the number of cents is 00004, to put in a decimal point and generate a result of .04.

-

2-106 User Operations

MESSAG + n 1 n Insert Message Character

0 2 3 8

If S is 1 place the character from EO + n + 1 in the next destination position.

Otherwise if location EO+ 1 is nonzero, place the fill character from it in the next destination position.

FLDSEP 11 Separate Fields

0 8

Clear S, M and N.

Notes. Essentially this instruction causes the procedure to start over on a new substring. A typical use would be in handling a series of numbers (separated by some character), where one would want to suppress leading zeros in all of them.

EXCHMD

I

004 Exchange Mark and Destination Pointers

0 8

Interchange the destination pointer presently held in AC +4,AC + 5 with the mark pointer at the location specified by the mark address.

Notes. This makes it possible to go back to where significance began in order to revise the destination string in light of further processing of the source, but at the same time saving the present position. A return forward can be made simply by repeating the instruction.

Note that it is unlikely to be very useful for the programmer to set up an initial mark pointer. In any normal procedure a mark is created from the destination pointer and is simply a particular state of it. Hence the destination and mark pointers have the same number of words. The result is indeterminate if the programmer deliberately sets up mark and destina- tion pointers of different types.

SKPM + n [] Skip on M

0 2 3 8

If M is 1 skip over the next n + 1 pattern commands by incrementing the pattern pointer n + 1 times.

Notes. M is generally used as a minus sign, i.e. to indicate a string is negative, but the programmer can use it for any purpose. A typical use would be to determine whether ‘CR” or “DB” should be inserted after a number.

SKPN + n 1611 Skip on N

0 2 3 8

If N is 1 skip over the next n + 1 pattern commands by incrementing the pattern pointer n + 1 times.

User Operations Z-107

Notes. N is generally set to mean the string is nonzero, but the pro- grammer can use it for any purpose. Suppose we wish to output a blank on zero, but use of SIGST to handle cents-only quantities has produced “.OO”.

We could use SKPN after the last source byte, so that if the output is nonzero we would skip over commands that would otherwise go back and blank the output.

SKPA + n 7 1 I1 Skip Always

0 2 3 8

Skip over the next n + 1 pattern commands by incrementing the pattern pointer n + 1 times.

Notes. This command is used mostly to reverse the meaning of the other skips. For example, the sequence “SKPN,X” skips command X if N is 1, but the sequence “SKPN,SKPA,X” executes it if N is 1. SKPA can also be used to extend a conditional skip beyond sixty-four commands, as in

SKPN + 77 ,... 63 bytes... ,SKPA,SKPA + 3,. . .4 bytes.. . ,X

in which N being 1 causes a skip over sixty-seven significant commands to get to X.

NOP 005 No-op

0 II

Do nothing.

STOP I 000 ] Stop Edit

0 8

Increment the pattern pointer, end the edit, and skip the next instruction.

At the end the byte pointers point to the last positions referenced in source and destination, and the pattern pointer points to the command byte following the last one executed. Note 1 owever that if the pattern gives an EXCHMD after the final byte is placed ;n the destination string, the “desti- nation pointer” is actually at the mark location rather than in AC +4,AC + 5. If unused interior bits n both strings are clear initially, they are left clear; otherwise unused in ,erior destination bits are indeter- minate. The source string is unaffected.

Notes. If an interrupt or page failurt occurs during EDIT, the accumu- lators are adjusted for restarting at the beginning of the current pattern command.

-

-

2-108 User Operations

Figure 2.2: Edit Instruction

-

Example. The following program uses binary-to-decimal conversion and editing to translate a binary number into a message of seventeen char- acters containing a decimal string with appropriate nomenclature for com- mercial billing purposes. A positive result has the form

ACB,[POINT 7,TEMPl ;Pointer for source string

; (CVTBDO result) AC4,MARK ;Address of mark pointer AC5,lPOINT 7,FIELDl ;Pointer for destination string ACl,EDTINS ;Edit the item

;Here is the translation table. Digits l-9 set S and N flags; 0 does not affect the flags

Before continuing to more system-related subjects, let us consider some simple programs that demonstrate the use of a variety of the instructions

Im Dokument UPDATE NOTICE (Seite 164-172)