… TABLE DS 30CL75 TABREC DS CL75 RECLEN EQU *-TABLE DS 29CL75
“Bumping” a DSECT
Exercise #5 Create a static table of states and zipcode ranges in your program Create and read a file of 5-digit zip codes (one zip per record) Search for each zip code in the given ranges of the table. Print out the corresponding state or a message indicating the zip is invalid
Exercise #5
Exercise #5A Use BCST.SICCC01.PDSLIB(EXER5A) which has 80 byte records in the following format: CUSTNO – cols 1-5 character CUSTBAL – cols 6-9 packed (dollars and cents) Read the data into a table in your program. After reading the entire file, process the table by printing a report that lists customer numbers and balances. Process the table again and print a second report that lists all the customer numbers with a negative balance.
Standard Entry Code MAIN CSET STM R14,R12,12(R13) BASR R12,R0 USING *,R12 ST R13,SAVE+4 LA R13,SAVE
Store Multiple STM RS Op 1 – Beginning register of a range Op 2 – Ending register of a range Op 3 – a Fullword in memory Consecutive fullwords starting at Op-3 are loaded into consecutive registers beginning with Op 1.
STM
BASR BASR – Branch and Save Register Op 1 – A register Op 2 – A register The address of the next instruction is stored in Op 1, and a branch occurs to the address in Op 2. If Op 2 is Register 0, no branch occurs
USING A directive that determines 1) The base register(s) 2) The base address from which all displacements are computed Op 2 – a register (or range) that will be used for base registers
USING Terms The domain of a USING directive starts at the USING statement and continues until the end of the program or until all registers mentioned in the USING are dropped USING *,R12 …. DROP R12
USING Terms The range of a USING starts at the base address and continues for 4K USING *,R12 HERE EQU * … USING HERE,R12
Addressability Rules Each variable symbol must be defined in the range of a USING statement Each use of a variable symbol must occur in the domain of the corresponding USING statement
Linkage Conventions Calling Program Conventions Put the address of the target program in R15 Put the return address in R14 Put the address of the save area in R13 Put the address of the list of parameter addresses in R1
Linkage Conventions Called Program Conventions Store the calling programs registers in the calling program’s save area Use R1 to access the parameters that were passed For a function subprogram, return the answer in R0 Put a return code in R15
Passing Parms
Standard Exit Code L R13,SAVE+4 OLD SAVE AREA LM R14,R12,12(R13) RESET REGS BR R14 BRANCH BACK
Exercise #6 Create a subprogram that is passed 4 variables, A, B, C, and D. Compute (A*B)+C rounded to 2 decimals. Return the answer in D Assume each field is PL3 with 2 decimals Write a calling program that reads a file, passes four parameters to your subprogram and prints a report listing the value of each variable A, B, C, and the computed value D.
Working With Large Data Fields
Insert Character RX Copies a single byte from memory (first byte) into the rightmost byte of a register Before: R5 After: R5 IC R5,X 00 11 22 33 00 11 22 aa aa bb cc aa bb cc X X
Store Character RX Copies a single byte from the rightmost byte of a register into memory Before: R5 After: R5 STC R5,X 00 11 22 33 00 11 22 33 aa bb cc 33 bb cc X X
Insert Characters Under Mask RS Copies a consecutive bytes from memory (1-4 bytes) into the bytes of a register based on a binary mask. ICM R5,B’1010’,X Before: R5 After: R5 00 11 22 33 aa 11 bb aa aa bb cc aa bb cc X X
Insert Characters Under Mask ICM is sometimes used to load a word or halfword into a register from a memory location that isn’t aligned on a halfword or fullword boundary ICM R7,B’0011’XWORD
Store Characters Under Mask RS Copies bytes of a register based on a binary mask into consecutive bytes of memory (1-4 bytes) . STCM R5,B’1010’,X Before: R5 After: R5 00 11 22 33 00 11 22 33 aa bb cc 00 22 cc X X
MVCL – Move Characters Long Used to move data in storage provided the source and target don’t overlap Uses four registers, two even/odd pairs Op 1 even register contains the target address Op 1 odd register contains the length of Op 1 Op 2 even register contains the source address Op 2 odd register contains the length of Op 2 Op 2 contains a pad byte in the first 8 bits
MVCL – Move Characters Long Case 1: L1 > L2 Before execution: R4 R5 R6 R7 A(A) 1000 A(B) x’40’ 500 After execution: R4 R5 R6 R7 A(A) + 1000 0 A(B) + 500 x’40’ 0 Padding occurs with 500 blanks (x’40’)
MVCL – Move Characters Long Case 1: L1 < L2 Before execution: R4 R5 R6 R7 A(A) 500 A(B) x’40’ 1000 After execution: R4 R5 R6 R7 A(A) + 500 0 A(B) + 500 x’40’ 500 No padding occurs
MVCL – Move Characters Long Case 1: L1 = L2 Before execution: R4 R5 R6 R7 A(A) 1000 A(B) x’40’ 1000 After execution: R4 R5 R6 R7 A(A) + 1000 0 A(B) + 1000 x’40’ 0 No padding occurs
MVCL – Move Characters Long MVCL does not permit sending and receiving fields to overlap MVCL sets the condition code: - CC = equal Fields equal in size
- CC = low Size of field 1 < size of field 2
- CC = high Size of field 1 > size of field 2
- CC = overflow Fields overlapped
- Test with BE, BL,BH, BO
MVCL Sample Code L R5,LENGTHA PUT LENGTH OF TARGET IN ODD REG LA R6,FIELDB POINT AT SOURCE FIELD WITH EVEN REG L R7,LENGTHB PUT LENGTH OF SOURCE IN ODD REG ICM R7,B’1000’,BLANK INSERT BLANK PAD CHAR IN ODD REG MVCL R4,R6 … FIELDA DC CL2000’ ’ BDATA DC 1000CL1’X’ ORG BDATA FIELDB DS CL1000 LENGTHA DC A(L’FIELDA) CREATE ADDR CON AS LENGTH LENGTHB DC A(L’FIELDB) CREATE ADDR CON AS A LENGTH BLANK DC C’ ’
Blanking an Area with MVCL LA R8,TARGET L R9,TARLEN LA R4,SOURCE SOURCE DOESN’T PARTICIPATE LA R5,0 SET LENGTH OF SOURCE TO 0 ICM R5,B’1000’,BLANK SET PAD TO A BLANK MVCL R8,R4 COPY BLANKS
CLCL - Compare Long Long fields can be compared using CLCL Just like MVCL, the setup involves two even/odd pairs for the source and target fields As long as the compared bytes are equal, CLCL adds 1 to the addresses in the even registers and decrements the odd registers by 1
CLCL - Compare Long Unequal bytes causes the operation to terminate with the address of the unequal bytes in the even registers and the condition code is set (equal, low, high, overflow) The pad character can be supplied for unequal sized fields and each pad character participates in the comparison
Using Multiple Base Registers An “ideal” program will have a single base register Few programs are “ideal” Many programs require multiple base registers Providing multiple base registers is a two step process - The registers are declared in a USING
- Each register must be loaded with it’s base address
Using Multiple Base Registers There are as many ways to load base registers as there are programmers. Here’s a simple approach to load 3 registers: BASR 12,0 USING *,12,11,10 LA R10,2048 LA R11,2048(R10,R12) LA R10,2048(R10,R11)
Exercise #7 Create a program that contains three 2000 byte fields. Define the fields like this: FIELDA 0DS CL2000 DC 2000C’A” FIELDB 0DS CL2000 DC 1000C’A’ DC 1000C’B’ FIELDC DC CL2000’ ’
Exercise #7 Move FieldB to FieldC. Print out FieldA, FieldB and FieldC in a series of 100 byte lines (use DSECTs) Compare FieldA to FieldC and print a message indicating which one is larger. You may find this helpful: ALEN DC A(L’FIELDA) BLEN DC A(L’FIELDB) CLEN DC A(L’FIELDC)
Working With Variable Length Data
Parm Data Here is some JCL that passes a parm //COND00A EXEC PGM=JCLCONC1, // PARM=‘THE MESSAGE' Here is the data structure the parm creates Reg 1
Processing the Parm Data PARMSECT DSECT LEN DS H PARMDATA DS CL256 USING PARMSECT,R8 LH R9,LEN GRAB THE PARM LEN BCTR R9,R0 SUB 1 FOR LENGTH EX R9,MOVE MOVE THE DATA … MOVE MVC PARMOUT(0),PARMDATA
Notes on Processing Parm Data The target MVC is coded like this MOVE MVC PARMOUT(0),PARMDATA An explicit length of zero allows the “OR” operation of EX to “copy” a length into the target instruction temporarily Rightmost byte of R9 is “OR-ed” into the second byte of the target instruction (the length) EX R9,MOVE executes the MVC out of line
Exercise #8 Write a program that prints the parm data it is passed through JCL Run the program three times with these JCL EXEC statements: //COND00A EXEC PGM=JCLCONC1,PARM=‘THE' //COND00B EXEC PGM=JCLCONC1,PARM=‘THE MESSAGE‘ //COND00C EXEC PGM=JCLCONC1,PARM=‘ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Variable Length Records Variable length records are described in the DCB with RECFM=VB or RECFM=V When the record is read, it arrives with a Record Descriptor Word (RDW) at the beginning. The RDW consists of two halfwords, the first is unused and the second contains the length of the record including the RDW
The input buffer you define has to be large enough to accommodate the largest record + the RDW It could be defined like this: DS 0F ALIGNMENT MYREC DS 0CL124 RDW DS 0F DS H RECLEN DS H DATA DS CL120
Reading VB or V Records After reading the record, load the RECLEN into a register Subtract 4 from the register to account for the RDW Use EX to execute an MVC to an output area
Processing V or VB Records L R8,RECLEN S R8,=F’4’ EX R8,TARGET PUT MYFILE,RECOUT … TARGET MVC RECOUT(0),DATA
Writing V or VB Records Move the data to your output buffer. We can reuse MYREC. Determine the number of bytes in the record. Add for for the RDW. Store the record length + 4 in RECLEN PUT the record
Exercise #9 Read the file BCST.SICCC01.PDSLIB(EXER9) which has records in the following format: Cols 1-2 Length in Character format Cols 3-80 Data Write a program with reads the file as 80 byte records and writes out a VB file using the length of each record to detemine how much data to write
Exercise #10 Read the file VB file you produced in Exercise 9. Print each record using the length that is delivered in the RDW
Translate There is a special instruction for translating strings of characters called Translate (TR) Using TR you can easily convert a string or file from one format to another. For example ASCII to EBCDIC or lowercase letters to uppercase letters. One of the difficulties of using TR is that it requires you to build a table of values that indicate by there position how the translation will proceed
Translate In many cases you are interested in only changing a few of the values. For example, you may only want to change the 26 lowercase letters to uppercase. In these cases, there is an easy way to build the required table.
Translate SS1 The first operand is the memory location that contains the data to be translated. Each byte in the string we are translating is used as a displacement into the table. The corresponding table byte replaces the byte we are translating. Translation occurs from left to right in operand 1
Translate TR X,MYTABLE X (Before) X (After) 03 02 01 C4 C3 C2 C1 C2 C3 C4 C5 MYTABLE
Translate Since the string you are translating might contain any of 256 possible patterns, most TR tables have 256 bytes. Here is a table that translates every byte to itself: MYTABLE DC 256AL1(*-MYTABLE) Starting with this as a basis, you can ORG back into the table to change the values you are really interested in.
Translate Here is a table that translates digits to blanks: MYTABLE DC 256AL1(* - MYTABLE) ORG MYTABLE+C’0’ DC CL10’ ‘ ORG
Exercise #11 Write a program that reads and prints a file called BCST.SICCC01.PDSLIB(EXER11) which contains records in lowercase letters (other characters, too). For each record, translate it to uppercase before printing the record.
Translate and Test TRT is somewhat misnamed as no translation occurs automatically. Instead, TRT is used to find character bytes that we are searching for. For example, TRT could be used to find a comma in a record, or the first blank. Like TR, TRT requires the programmer to build a TRT table
Translate and Test TRT tables are related to TR tables, but the semantics of the statement is different. Like TR the byte we are translating is used as a displacement into a table. If the table byte we find is X’00’, translation continues,otherwise translation terminates Finding any non-X’00’ byte stops the translation and test.
TRT TRT sets the condition code to indicate the results of the operation: ( Zero ) All function bytes encountered were X’00’. ( Minus ) A nonzero function byte was found before the end of operand 1 ( Positive ) A nonzero function byte was found at the end of the operand 1
TRT Scan for $ or ? TABLE DC 256AL1(0) ORG TABLE+C’$’ Scan for $ DC X’FF’ ORG TABLE+C’?’ Scan for ? DC X’FF’ ORG … TRT MYSTRING,TABLE BZ NOTFND
TRT Sets Regs 1 and 2 If the TRT process finds a non X’00’ table byte (function byte), Reg 1 will be set with the address of the byte from the string that was used to find a non-zero function byte If the TRT process finds a non X’00’ table byte (function byte), Reg 2 will set the function byte into the rightmost byte of the register. Coding this will move the function byte to the string: STC R2,0(R0,R1)
Testing Numerics with TRT TABLE DC 256X’FF’ ORG TABLE+X’F0’ ORG Suppose we want to test a field called “FIELD” to see if it is numeric in the sense described above. This can be accomplished as follows. TRT FIELD,TABLE BZ ALLNUMS B NOTNUMS
Exercise #12 Read and print file BCST.SICCC01.PDSLIB(EXER12) Each record contains a last name, a comma, first name, #. Print each name as first name, space, last name. This will require working with variable length data and some address arithmetic in the registers.
Dostları ilə paylaş: |