Upload
krystal-meeth
View
151
Download
7
Tags:
Embed Size (px)
DESCRIPTION
IBM Assembly 370 Programming Introduction Manual. This is a terrific guide for beginning to learn mainframe IBM assembler 370 programming language./
Citation preview
IBM Mainframe Assembler Language Coding
EXERCISE #8
PROGRAM 8.
Decimal arithmetic.
Modify the last "working" program calculating
gross pay and overtime / or average weekly pay
to use Packed Decimal calculations.
No changes to input or output format.
Use a new shell program to start -or-
211
Use a new shell program to start -or-
copy the working program and modify it.
IBM Mainframe Assembler Language Coding
212
IBM Mainframe Assembler Language Coding
Creating Edited Output
There are two instructions in IBM Assembler that provide options for producing readable output on a printed report or terminal screen display.
These options include:
1. Insertion of a decimal point in the appropriate position.
2. Replacement of leading zeros by blanks.
3. Insertion of commas or other characters to improve the readability of the output.
213
readability of the output.
4. Use of blank space instead of a plus sign for positive numbers.
5. Use of either a CR or a minus sign suffix for identifying negative numbers.
The two instructions used are the EDIT (ED) and the EDIT AND MARK (EDMK). Each of these convert a packed-decimal number to printable EBCDIC code and insert editing characters as specified. They perform this task by means of a concept known as a pattern.
IBM Mainframe Assembler Language Coding
Pattern
A pattern is made up of the following elements:
– a fill character (always the 1st byte of the pattern)
– text characters (comma, period/decimal point, etc.)
– special editing symbols:
» X'20' Digit selector - causes the current digit to be taken from the number being operated on. If the digit is non-zero (significant) then it will replace the digit selector in the pattern. Otherwise, the digit selector is replaced by the fill character.
214
replaced by the fill character.
» X'21' Significance starter - selects the current digit just as the digit selector does, but it also forces all subsequent digits to be considered significant. If the current
digit is significant, it replaces the significance starter; else the fill character replaces it.
IBM Mainframe Assembler Language Coding
Editing Example
The pattern and the packed-decimal number are processed left to right. Each byte of the pattern (or result field) either is left unchanged or is replaced. If replaced, it is replaced by the current packed decimal digit or by the fill character of the pattern.
DD DD DD DS
SOURCE
PATTERN
215
FC DS DS DS SS DS 4B DS DS
PATTERN
IBM Mainframe Assembler Language Coding
Edit
MVC RESULT,PATTERN
ED RESULT,SOURCE
00 34 06 7C
SOURCE
PATTERN
216
40 20 20 20 20 21 4B 20 20
40 40 40 F3 F4 F0 4B F6 F7
RESULT
3 4 0 . 6 7
IBM Mainframe Assembler Language Coding
Edit
MVC RESULT,PATTERN
ED RESULT,SOURCE
00 00 00 1C
SOURCE
PATTERN
217
40 20 20 20 20 21 4B 20 20
40 40 40 40 40 40 4B F0 F1
RESULT
. 0 1
IBM Mainframe Assembler Language Coding
Edit
MVC RESULT,PATTERN
ED RESULT,SOURCE
01 23 45 6C
SOURCE
PATTERN
218
40 20 20 6B 20 20 21 4B 20 20 40 60
40 40 F1 6B F2 F3 F4 4B F5 F6 40 40
RESULT
1 , 2 3 4 . 5 6
IBM Mainframe Assembler Language Coding
Edit
MVC RESULT,PATTERN
ED RESULT,SOURCE
00 00 02 9D
SOURCE
PATTERN
219
40 40 40 40 40 40 F0 4B F2 F9 40 60
40 20 20 6B 20 21 20 4B 20 20 40 60
RESULT
0 . 2 9 -
IBM Mainframe Assembler Language Coding
Edit and Mark - EDMK
The only difference between the way the EDIT (ED) and the EDIT AND MARK (EDMK) work is that the EDMK allows you to float a dollar sign to the position you desire.
When the significance indicator is off and a significant digit is detected, the address of the corresponding pattern byte is placed into register 1. This address can then be used to insert a dollar sign into the pattern at the desired location. Hence the dollar sign “floats”.
There are two task programmers must perform with the EDMKinstruction:
220
1. The address of the pattern byte immediately following the significance starter should be placed into register 1 before the EDMK instruction is executed.
2. After the EDMK is executed, the address in register 1 must be reduced by 1 in order for the ensuing MVI to place the dollar sign in the byte immediately preceding the first significant digit.
IBM Mainframe Assembler Language Coding
Edit and Mark
MVC RESULT,PATTERN
LA R1,RESULT+6
EDMK RESULT,SOURCE
SH R1,=H'1'
MVI 0(1),C'$'
00 00 02 9C
SOURCE
221
40 20 20 6B 20 21 20 4B 20 20 40 60
PATTERN
40 40 40 40 40 40 F0 4B F2 F9 40 40
RESULT
$ 0 . 2 9
IBM Mainframe Assembler Language Coding
Edit and Mark
MVC RESULT,PATTERN
LA R1,RESULT+3
EDMK RESULT,SOURCE
BCTR R1,R0
MVI 0(R1),C'$'
12 88 8C
SOURCE
222
40 20 21 20 4B 20 20 40 60
PATTERN
RESULT
$ 1 2 8 . 8 8
40 F1 F2 F8 4B F8 F8 40 40
IBM Mainframe Assembler Language Coding
EXERCISE #9.
PROGRAM 9.
Edited output
Modify a working gross pay calculation program
to produce edited output.
Floating $
. decimal point required
, comma if required by the result data
223
Suppress leading zeros before decimal point
zero wages = $.00
IBM Mainframe Assembler Language Coding
224
IBM Mainframe Assembler Language Coding
TR D1(L,B1),D2(B2)
The Translate instruction uses each byte of the first operand, or 'argument', as an offset to the second operand, or 'table', telling where to go for a new value. Each new value replaces the byte that was used as an offset in the 1st operand.
This instruction can be used to translate EBCDIC to ASCII, lowercase to upper, and punctuation marks to some other desired character.
The Translate Instruction
225
TR ARGUMENT,TABLE
04 01 03 C1 C2 C3 C4 C5 C6 C7
Before
ARGUMENT TABLE
C5 C2 C4 C1 C2 C3 C4 C5 C6 C7
After
ARGUMENT TABLE
IBM Mainframe Assembler Language Coding
The Translate Instruction
Change ASCII uppercase characters in the input message to their EBCDIC counterparts.
TR INPUT,TABLE
TABLE DC 65XL1'00'
DC C'ABCDEFGHIJKLM'
DC C'NOPQRSTUVWXYZ'
Change EBCDIC uppercase characters in the input message to their lowercase counterparts.
226
TR INPUT,TABLE2
TABLE2 DC 256AL1(*-TABLE2)
ORG TABLE2+C'A'
DC C'abcdefghi'
ORG TABLE2+C'J'
DC C'jklmnopqr'
ORG TABLE2+C'S'
DC C'stuvwxyz'
ORG
IBM Mainframe Assembler Language Coding
The Translate and Test Instruction
TRT D1(L,B1),D2(B2)
The Translate and Test instruction uses each byte of the first operand, or 'argument', as an offset to the second operand, or 'table', telling where to go for a value. This value is used to determine the continuation of the operation. If the selected value is zero (X'00'), then the operation continues by fetching and translating the next byte of the first operand, with registers 1 & 2 remaining unchanged.
If the value selected is non-zero, the following occurs:
1. The address of the byte from the first operand that was found to be non-zero in the table is loaded into register 1.
2. The value from the table that was non-zero is placed in the low
227
2. The value from the table that was non-zero is placed in the low order bits (24-31) of register 2. The high order bits (0-23) of register 2 remain unchanged.
Unlike the translate instruction, the first operand is not changed. Usually the Translate and Test instruction is used to search a field for a specific character.
Condition codes:
CC = 0 All bytes of the 1st operand were found to be zero in the table.
CC = 1 A non-zero byte was found in the table before reaching the end of the first operand.
CC = 2 The last byte of the first operand was found to be non-zero in the table.
CC = 3 Not used.
IBM Mainframe Assembler Language Coding
The Translate and Test Instruction (cont.)
TRT ARGUMENT,TABLE
04 01 03 00 C1 00 00 00 00 00
Before
ARGUMENT TABLE
00 00 00 00 00 00 00 00
228
REG 1 REG 2
04 01 03 00 C1 00 00 00 00 00
After
ARGUMENT TABLE
addr 2nd byte
argument00 00 00 C1
REG 1 REG 2
CC = 1
IBM Mainframe Assembler Language Coding
The Translate and Test Instruction (cont.)
TRT ARGUMENT,TABLE
04 01 03 00 00 00 00 00 00 C1
Before
ARGUMENT TABLE
00 00 00 00 00 00 00 00
REG 1 REG 2
229
REG 1 REG 2
04 01 03 00 00 00 00 00 00 C1
After
ARGUMENT TABLE
00 00 00 00 00 00 00 00
REG 1 REG 2
CC = 0
IBM Mainframe Assembler Language Coding
The Translate and Test Instruction Table
Look for a plus sign (+) in an input line.
TRT INPUT,TABLE3
TABLE3 DC 256XL1'00'
ORG TABLE3+C'+'
DC X'FF'
ORG
230
IBM Mainframe Assembler Language Coding
Move Character Long
MVCL R1,R2
The Move Characters Long instruction can cause data movement of fields exceeding the 256 byte limit of the MVC. A total of 4 registers will be used by this instruction. The “even-odd” register concept is used -the 2 even registers will contain the addresses of the fields involved, and the odd registers will contain the lengths.
The contents of the register pairs are altered during the execution of this instruction. At completion, the length field in register R1 + 1 is zero and the address in R1 has been incremented by the original length in R1 + 1. The length field in register R2 +1 has been decreased by the number of bytes copied from the receiving field, and the address in R2 has been incremented by the same amount.
231
Movement is from left to right and ends when the number of bytes specified by the first operand (R1+1) has been moved.
If the MVCL is to be used in a loop, the program must reload the registers after each iteration of the loop.
As part of execution, the values of the two lengths are compared for the setting of the condition code.
Condition Codes:
CC = 0 1st and 2nd operand counts are equal
CC = 1 1st operand count low
CC = 2 1st operand count high
CC = 3 no movement - destructive overlap - occurs when 1st operand byte is used as a source after data has been moved into it.
IBM Mainframe Assembler Language Coding
Move Character Instructions
MVCL - The Move Character Long copies L bytes of data (where L <= 224 -1) from the memory location designated by bits 8-31 of the generalregister specified in the 2nd operand to thememory location designated by bits 8-31 of thegeneral register specified by the 1st operand.This results in a byte-for-byte move. The MVCLrequires 4 registers - 2 sets of even/odd pairs.
MVCL R1,R2
232
IBM Mainframe Assembler Language Coding
Move Character Long
Example: Clearing 500 bytes to blanks.
LA R4,LONGONE
LA R5,500
LA R6,LONGONE
L R7,SPACEPAD
MVCL R4,R6
.
.
.
.
DS 0F
233
DS 0F
SPACEPAD DC X'40000000'
LONGONE DS CL500
IBM Mainframe Assembler Language Coding
Move Character Long
MVCL R4,R6
00 02 08 50 00 00 01 F4
40 00 00 0000 02 08 50
REG 4 Addr. 1st op. REG 5 Length 1st op.
REG 6 Addr. 2nd op. REG 7 Length 2nd op.
****** BEFORE ******
234
REG 6 Addr. 2nd op. REG 7 Length 2nd op.
00 02 0A 44 00 00 00 00
40 00 00 0000 02 08 50
REG 4 Addr. 1st op. REG 5 Length 1st op.
REG 6 Addr. 2nd op. REG 7 Length 2nd op.
****** AFTER ******
IBM Mainframe Assembler Language Coding
Move Character Long
Example: Destructive Overlap
(Would execute as a MVC instruction.)
LA R4,TARGET Rec fld addr
LA R5,20 Rec fld length
LA R6,TARGET-10 Send fld addr
L R7,PADLENTH Send fld length
MVCL R4,R6 c.c. = 3
.
.
.
235
.
DS OF
PADLENTH DC X'F0000014'
OUTLINE DS CL50
TARGET DS CL50
IBM Mainframe Assembler Language Coding
Move Character Long
Example: Non-Destructive Overlap
LA R4,TARGET-10 Rec fld addr
LA R5,20 Rec fld length
LA R6,TARGET Send fld addr
L R7,PADLENTH Send fld length
MVCL R4,R6 c.c. = 0
.
.
.
DS OF
PADLENTH DC X'F0000014'
236
PADLENTH DC X'F0000014'
OUTLINE DS CL50
TARGET DS CL50
IBM Mainframe Assembler Language Coding
Compare Logical Character Long
CLCL R1,R2
The Compare Logical Characters Long can test equal or unequal length fields. When comparing unequal length fields, a padding character is used to even the two fields temporarily.
The "even-odd" register concept is used - the 2 even registers will contain the addresses of the fields involved, and the odd registers will contain the lengths.
237
IBM Mainframe Assembler Language Coding
CLCL 4,2
STORAGE:
Compare Logical Character Long (cont.)
00 00 82 5E 00 00 00 0C
REG 4 Addr. 1st op. REG 5 Length 1st op.
40 00 00 0900 00 53 A2
REG 2 Addr. 2nd op. REG 3 Length 2nd op.
Before:
238
STORAGE:825E - C1 E2 E8 D3 C4 40 C7 D5 40 E2 F3 F8
53A2 - C1 E2 E8 D3 C4 40 E6 F3 F9
00 00 82 64 00 00 00 06
REG 4 Addr. 1st op. REG 5 Length 1st op.
40 00 00 0300 00 53 A8
REG 2 Addr. 2nd op. REG 3 Length 2nd op.
After:
CC = 1
IBM Mainframe Assembler Language Coding
Miscellaneous Directives
Print on - a program listing will be created (default).
Print Off - no program listing will be created.
Print Gen - All statements generated by a macro are printed.
Print Nogen - No statements generated by a macro areprinted (default).
Print Data - Constants are printed in full in the listing.
Print Nodata - Constants are not printed in full in the listing.
239
Print Nodata - Constants are not printed in full in the listing.Only the first 8 bytes will be printed (default).
Push Print - This suspends the most recently establishedkey words of a print directive.
Pop Print - This restores the key words of the mostrecently suspended print directive.
E.g. PRINT ON,NOGEN,NODATA
IBM Mainframe Assembler Language Coding
Table Search and Program Loop Control
Programs use tables to define sets of values and to reference those values during program execution. A program table, sometimes called an array, contains a set of related values which can be referenced based on one or more variables.
Each position in a table is called a table entry. The data items in a table are called table elements. There are two types of elements - the argument and the function. When using a variable to search the table argument, the variable is called a search argument.
240
IBM Mainframe Assembler Language Coding
Table Search and Program Loop Control example:
LA R3,FLTTABL SPECIAL FLIGHT TABLE
LA R4,#ENTRIES NBR OF ENTRIES IN TABLE
MVI SWITCH,X'00' RESET SWITCH
FLTLOOP EQU *
CLC FLTNUM,0(R3) LOOK FOR SPECIAL FLIGHT
BE SWITCHON YES-GO TURN SWITCH ON
LA R3,L'TABLNTRY(R3) NO-POINT TO NEXT TBL ENTRY
BCT R4,FLTLOOP LOOP BACK
B BYPASS NO SPECIAL FLIGHT FOUND
SWITCHON EQU *
MVI SWITCH,X'FF' FOUND IT
BYPASS EQU *
.
.
241
.
.
FLTTABL EQU *
TABLNTRY DC C'012'
DC C'104'
DC C'255'
DC C'381'
DC C'510'
#ENTRIES EQU (*-FLTTABL)/L'TABLNTRY
.
(In a work block - not in the program)FLTREC DS 0CL80
FLTNUM DS CL3
.
.
.
SWITCH DS X
IBM Mainframe Assembler Language Coding
Table Search and Program Loop Control Example:
LA R3,FLTTABL POINT TO FLIGHT TABLE
LA R4,NBRNTRYS NBR OF ENTRIES IN TABLE
FLTLOOP EQU *
CLC FLTNBR,0(R3) DO WE HAVE A HIT?
BE PROCESS YES
LA R3,L'FRSTNTRY(R3) NO-POINT TO NEXT ENTRY
BCT R4,FLTLOOP LOOP BACK
B BYPASS
PROCESS EQU *
MVC 4(L'PAXNBR,R3),PAXNBR
BYPASS EQU *
.
.
(This table is in a data record - not in the program)
242
(This table is in a data record - not in the program)
FLTTABL EQU *
FRSTNTRY DS CL8'1098XXXX' * CURRENT
DS CL8'3031XXXX' * CONTENTS
DS CL8'0821XXXX' * OF THE
DS CL8'5590XXXX' * FLIGHT
DS CL8'0327XXXX' * TABLE
NBRNTRYS EQU (*-FLTTABL)/L'FRSTNTRY
.
.
.
FLTREC DS 0CL80
FLTNBR DS CL4
PAXNBR DS CL4
IBM Mainframe Assembler Language Coding
EXERCISE #10.
PROGRAM 10.
Edit file input records using TRT.
Input: Records accessed by GET macro.
Each record has a name field, a numeric
reference code and a complaint count.
nameeeeee ### #otherdataotherdata
Process: Validate that the name field contains only
243
Process: Validate that the name field contains only
alpha characters or blanks (use TRT).
Valid record - count it, save the name and
numeric reference number for
later display, accumulate the
number of complaints.
Invalid record - count it and get another record.
Output: Display the numeric reference in col 1.
followed by a blank followed by the name.
(more)
IBM Mainframe Assembler Language Coding
EXERCISE #10 (continued)
OUTPUT (continued)
After all good record lines have been displayed, output a
blank line followed by (starting in col 4.) -
TOTAL:bGOODbnnbbBADbnnbbCOMPLAINTSbnn….
b = blank space.
nn = totals of records or complaints.
Miscellaneous:
244
Miscellaneous:
Maximum input records = 20.
Write program ZOO5ii (new shell ZOO5II).
Prior to testing LOAD -
ZOO1IE ZOO8II ZOO9IE ZOOAIE
From T1 screen on small test system enterB@INIT
(response is DATABASE INITIALIZED)
After GET macro, R1 will point to first byte of an input
record UNLESS R1 is zeros which means no more input
records.
To test your code - b@alc3+
IBM Mainframe Assembler Language Coding
Exercise 1 - Data Definition
For this exercise, code the appropriate DS or DC statement in the "skeleton"program that was sent to you. Rename the program to EXR1yi ("yi" means"your initials"). After you have finished coding the statements in the pro-gram, assemble it by using the PARSASM exec. Examine the object code toverify the accuracy of each instruction.
1. Define five 10-byte areas that will contain character type data.
2. Define a 6-byte area that will contain packed decimal data.
245
3. Define seven fullword data areas.
4. Define a binary constant with a value of hex C4. Use implied length.
5. Define two halfword constants, each with a value of -256.
6. Define 3 packed decimal constants containing the value of27, -9658, and 326. Each one will be 4 bytes long. Use onlyone data definition instruction for all three.
last updated 02/09/01
IBM Mainframe Assembler Language Coding
Exercise 1 - Data Definition
7. Define a 19 byte constant with the text: WSPN TRAINING CLASS
8. Define a constant with hex value 2171FACE.
9. Define eight zoned decimal constants, each of them 3 bytes long witha value of zero.
246
10. Define a 132 byte constant consisting of all blanks.
IBM Mainframe Assembler Language Coding
Exercise 2 - Move Instructions
For questions 1 - 9, show the contents of the fields requested after thegiven operation is performed. Each instruction builds on the previousone. Also, identify those instructions which are incorrectly coded.
To assemble this code with PARSASM place the following just after the"YOUR CODE GOES HERE" comment in your sample program.
DUMMY DSECT
JADE DS CL4
OPAL DS CL5
ROCK DS CL7
TOTAL DS CL4
DATA DS CL20
$IS$ CSECT
USING DUMMY,R4
LA R4,EBW000
MVC JADE,JADEC
MVC OPAL,OPALC
247
MVC OPAL,OPALC
MVC ROCK,ROCKC
MVC TOTAL,TOTALC
Follow the above instructions with those in the exercise.
Be sure the Define Constants go after all instructions.
JADEC DC CL4' '
OPALC DC CL5'STONE'
ROCKC DC CL7'DIAMOND'
TOTALC DC ZL4'1234'
1. MVC JADE,OPAL JADE:
2. MVC JADE+2(2),ROCK+3 JADE:
3. MVI ROCK,X'C6' ROCK:
4. MVC ROCK,OPAL+1 ROCK:
last updated 02/09/01
IBM Mainframe Assembler Language Coding
Exercise 2 - Move Instructions (cont.)
5. MVI OPAL(2),=C'A' OPAL:
6. MVC JADE,JADE JADE:
7. MVC ROCK-1(2),OPAL+1 OPAL:
ROCK:
8. MVC OPAL,=X'40' OPAL:
9. MVC JADE,X'40' JADE:
10. Write the code needed to take the 6 bytes that register 3is pointing to and move them 2 bytes past the address thatregister 5 is pointing to.
248
register 5 is pointing to.
11. Use one MVZ instruction to change the last byte of the valuein TOTAL to a printable numeric character.
TOTAL = X'F1F2F3C4'
12. Write the move instructions necessary to fill a 20 byte field called DATA with asterisks.
DATA DS CL20
IBM Mainframe Assembler Language Coding
Exercise 3 - Integer Arithmetic
Using the following data to answer the questions below. Code them in your sample program and load and test for results.
DS OF
FIRST DC XL8'0000007200000080'
SECOND DC H'12'
THIRD DC F'100'
FOURTH DC F'-25'
FIFTH DC H'16'
1. Put SECOND into register 5 and multiply it by literal 50.
249
2. Add FOURTH to register 5.
3. Divide the sum in register 5 by SECOND.
4. Subtract a halfword of 25 from the sum in register 5.
5. Square the sum found in register 5.
6. Add the last 4 bytes of FIRST to the sum in register 5.
7. Write the instructions necessary to compare the result obtained
with the value of FIFTH. What is the condition code setting?
IBM Mainframe Assembler Language Coding
250
IBM Mainframe Assembler Language Coding
Exercise 4 - Branching and Compares
Given the following CLC instruction, which branch (A or B) will be taken for each of the operand values defined in questions 1 to 5. Or if an exception or fall-thru occurs, please specify.
CLC OHIO,MAINE
A. BH CLEVELAND
B. BL BANGOR
1. OHIO DC C'ABC'
MAINE DC C'123'
251
2. OHIO DC X'51'
MAINE DC B'01010001'
3. OHIO DC C'121'
MAINE DC CL3'$$$'
4. OHIO DC P'25'
MAINE DC P'-25'
5. OHIO DC Z'-12'
MAINE DC C'-12'
last updated 12/29/99
IBM Mainframe Assembler Language Coding
Exercise 4 - Branching and Compares (cont.)
6. Write the compare logical instruction that will compare 7 bytes of data found 5 bytes from the beginning of the
address found in register 5, with 7 bytes of data pointed to by register 4. Include a branch instruction that will cause a branch to the tag NOGOOD when the result of the compare indicates that the first operand is either less than or greater than the second operand (use an extended mnemonic).
7. Code the following into your sample program, load and test it. Write the code necessary to add each element of tables X and Y
252
Write the code necessary to add each element of tables X and Y together storing the result in table Z. Write this
code using a BCT for loop control.
Data Definitions: X DC F'1,2,3,4,5,6,7,8,9,10,11,12'
Y DC F'1,2,3,4,5,6,7,8,9,10,11,12'
Z DS 12F
IBM Mainframe Assembler Language Coding
Exercise 5 - Load and Store
1. Increment register 3 by 8 without using a storage field.
2. Code a data area called REGAREA that is 16 fullwords long and the instruction that will place the contents of registers 0 - 7 into the data area beginning with the 4th fullword.
3. Put a X'C1' into the right-most byte of register 6 without affecting any other bytes.
4. Transfer the contents of register 15 into register 7.
253
5. Code a 5 byte field called BYTE5 and the instruction that will put the rightmost byte of register 5 into the middle byte of the field.
6. Code a 3 byte field called TEMP1 and the instruction that will place the address of the field into register 6.
7. Place into register 4 the contents of a fullword at SUM23 plus a displacement of 4.
8. True or False: Register 0 should never be used as a base register.
IBM Mainframe Assembler Language Coding
254
IBM Mainframe Assembler Language Coding
Exercise 6 - DSECT
Construct and assemble a DSECT that will consist of the followingfields:
• 10 bytes of non-essential data• 22 bytes reserved for character data• 5 bytes reserved for packed decimal data• 6 bytes reserved for character data• 7 bytes reserved for zoned decimal data• 7 bytes of non-essential data
After the assembly is complete, examine the listing to seethe effect a DSECT has on the location counter.
255
IBM Mainframe Assembler Language Coding
256
IBM Mainframe Assembler Language Coding
Questions 1 & 2 should be coded into your sample program and tested for results.
1. BIN1 has a value of B'00001000'
BIN2 has a value of B'00010000'
What is the value of BIN1 after each of these instructions (assume BIN1 has its original value for each instruction):
a.OC BIN1,BIN2
b.OI BIN1,B'00001000'
Exercise 7 - Altering Bits
257
c.OI BIN1,B'10000000'
d.OI BIN1,X'33'
2. BIN1 has a value of B'00001000'
BIN2 has a value of B'00010000'
What is the value of BIN1 after each of these instructions:
a.NC BIN1,BIN2
b.NI BIN1,B'11111110'
c.NI BIN1,X'80'
IBM Mainframe Assembler Language Coding
Exercise 7 - Altering Bits (cont.)
3. What value, if any, could be used to turn off all bits in a byte with an OR instruction?
4. You have just unpacked a field into OUT1, defined as CL7. Write the instructions needed to ensure that the sign indicator in the rightmost byte is equivalent to hex F.
5. Write an instruction to set TEMPFELD to binary zeros regardless of its current contents.
258
its current contents.
6. Write the instructions necessary to swap the values of TEMP1 and TEMP2without using any other storage areas.
IBM Mainframe Assembler Language Coding
Exercise 8 - Decimal Arithmetic
Given the following instructions and operand values, show the contents, in hex, of the result field. Also, identify those instructions which are incorrectly coded. Ignore the fact that TPF reentrant code will give you assembly errors.
1. MP CHANGE,STORE CHANGE DC PL6'60'
STORE DC PL3'6'
2. MP SAVE1,SAVE1+1(2) SAVE1 DC PL3'6'
259
3. DP FIELD1,FIELD2 FIELD1 DC PL7'10005'
FIELD2 DC PL3'100'
4. DP ABC,DEF ABC DC PL2'100'
DEF DC PL2'10'
5. DP X,Y X DC PL5'20245'
Y DC P'25'
IBM Mainframe Assembler Language Coding
Exercise 8 - Decimal Arithmetic (cont.)
6. SP CHANGE,STORE CHANGE DC PL3'60'
STORE DC PL1'6'
7. AP FIELD1,FIELD2 FIELD1 DC PL7'10005'
FIELD2 DC PL3'100'
8. AP ABC,DEF ABC DC PL2'100'DEF DC PL2'10'
260
9. SP X,Y X DC PL5'20245'Y DC P'25'
IBM Mainframe Assembler Language Coding
Exercise 9 - Decimal Data Operations
Given the following instructions and operand values, show the contents, in hex, of the result field. (Ignore reentrant issues.)
1. RATE DC CL4'8293'
PACK RATE,RATE RATE
2. INFO DC P'1734'
PACK INFO,INFO INFO
3. TEMP DC P'125'
DISC DC P'120'
ZAP TEMP,DISC TEMP
4.
261
4. INFO DC P'1734'
LAST DS CL6
UNPK LAST,INFO LAST
5. For the following instruction, what restriction applies to the field GREEN?
ZAP COLOR,GREEN
6. Code the instructions necessary to multiply MILES by RATE in packed decimal format. Declare any variables needed.
MILES DC CL3'241'
RATE DC CL2'18'
IBM Mainframe Assembler Language Coding
Exercise 9 - Decimal Data Operations (cont.)
7. Shift and round to dollars and cents the following value: 109237876452C
Assume the value given shows 5 digits to the right of the decimal point in a field named PKDNUM.
8. Given the following Compare Packed instruction, determine which branch (A, B, or C) will be taken for each of the operand values defined. If an exception occurs, please specify.
CP FLDA,FLDB
A. BE LABEL1
262
A. BE LABEL1
B. BL LABEL2
C. BH LABEL3
a. FLDA DC PL15'12'
FLDB DC P'16' BRANCH
b. FLDA DC P'-10652'
FLDB DC P'10652' BRANCH
c. FLDA DC P'-102'
FLDB DC X'0000102D' BRANCH
d. FLDA DC P'1'
FLDB DC P'201' BRANCH
e. FLDA DC P'300'
FLDB DC Z'300' BRANCH
IBM Mainframe Assembler Language Coding
Exercise 10 - Creating Readable Output
Show the results of the EDIT operations that use the following source field values and patterns. Indicate blank spaces with the lower case letter ‘b’.
SOURCE EDIT PATTERN RESULT
1. 0010000D 402020206B2020214B20606060
2. 04725C 4020204B202020
3. 00056D 5C20206B202020
4. 00002C 6020216B202020
263
5. 000C 40202021
6. 00014C 402021204B202040C3D9
7. 12001D 4020202020215C
8. Show the edit pattern required to print a 9 digit social security number with dashes between the 3rd and 4th, and the 5th and 6th characters. Do not suppress leading zeros of the SSN itself. Assume the SSN is in packed decimal format in a 6-byte field.
IBM Mainframe Assembler Language Coding
Exercise 10 - Creating Readable Output (cont.)
9. Write the edit pattern, output area and instructions required to edit a 7-digit source field. Provide for 'check protection (asterisk fill).
Use a comma and decimal point where needed and always print the two decimal positions. Print a static dollar sign.
Sample data: 0445681F
10.Convert a 5-byte packed field to a formatted result with 2 decimal positions. Always print the "ones" position and all digits to the right. Use a floating dollar sign plus commas and decimal points where needed. Also use a space followed by a minus sign to indicate negative amounts.
264
indicate negative amounts.
Sample data: 012019034D
IBM Mainframe Assembler Language Coding
Exercise 11 - Special Instructions
1. Write an instruction to test bits 0 and 1 in a one-byte field called BIN1. If both bits are on, branch to BOTHON; if only one is one, branch to ONEON. If neither is on, continue with the next instruction.
2. Write the MVCL instruction that will copy 381 bytes of data from the address contained in register 6 to the address contained in register 4. Also, write any other required preliminary instructions that will cause all registers to contain the proper values prior to execution of the MVCL instruction.
265
3. Write a move instruction moving GOAL to TARGET using length attribute (L') rather than the explicit or implicit length.
TARGET DS CL8
GOAL DC XL8'F1F2F3F4F5F6F7F8'
IBM Mainframe Assembler Language Coding
Exercise 11 - Special Instructions (cont.)
4. Write the translate table and the translate instruction that will take the constant shown below and translate the data to these values: F1 = A, F2 = B, F3 = C.
NUMBER DC X'F1F2F3F1F2F3F1F2F3'
266
5. Write an Execute instruction and a Move instruction using the combination of the two to move a variable amount of data. The length will be stored in a halfword field called VARDAT and the sending and receiving field addresses are stored in registers 6 and 10 respectively.