Sie sind auf Seite 1von 56

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 -orcopy the working program and modify it.

211

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. 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 packeddecimal number to printable EBCDIC code and insert editing characters as specified. They perform this task by means of a concept known as a pattern.

213

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. 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 is significant, it replaces the significance starter; else the fill character replaces it.

X'21'

digit

214

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.
SOURCE DD DD DD DS

PATTERN FC DS DS DS SS DS 4B DS DS

215

IBM Mainframe Assembler Language Coding


Edit

MVC ED

RESULT,PATTERN RESULT,SOURCE

SOURCE 00 34 06 7C

PATTERN 40 20 20 20 20 21 4B 20 20

RESULT 40 40 40 F3 F4 F0 4B F6 F7 3 4 0 . 6 7

216

IBM Mainframe Assembler Language Coding


Edit

MVC ED

RESULT,PATTERN RESULT,SOURCE

SOURCE 00 00 00 1C

PATTERN 40 20 20 20 20 21 4B 20 20

RESULT 40 40 40 40 40 40 4B F0 F1 . 0 1

217

IBM Mainframe Assembler Language Coding


Edit

MVC ED

RESULT,PATTERN RESULT,SOURCE

SOURCE 01 23 45 6C

PATTERN 40 20 20 6B 20 20 21 4B 20 20 40 60

RESULT 40 40 F1 6B F2 F3 F4 4B F5 F6 40 40 1 , 2 3 4 . 5 6

218

IBM Mainframe Assembler Language Coding


Edit

MVC ED

RESULT,PATTERN RESULT,SOURCE

SOURCE 00 00 02 9D

PATTERN 40 20 20 6B 20 21 20 4B 20 20 40 60

RESULT 40 40 40 40 40 40 F0 4B F2 F9 40 60 0 . 2 9 -

219

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 EDMK instruction: 1. The address of the pattern byte immediately following the significance starter should be placed into register 1 before the EDMK instruction is executed. 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.

2.

220

IBM Mainframe Assembler Language Coding


Edit and Mark
MVC LA EDMK SH MVI RESULT,PATTERN R1,RESULT+6 RESULT,SOURCE R1,=H'1' 0(1),C'$'

SOURCE

00 00 02 9C

PATTERN

40 20 20 6B 20 21 20 4B 20 20 40 60

RESULT

40 40 40 40 40 40 F0 4B F2 F9 40 40 $ 0 . 2 9

221

IBM Mainframe Assembler Language Coding


Edit and Mark

MVC LA EDMK BCTR MVI

RESULT,PATTERN R1,RESULT+3 RESULT,SOURCE R1,R0 0(R1),C'$'

SOURCE

12 88 8C

PATTERN

40 20 21 20 4B 20 20 40 60

RESULT

40 F1 F2 F8 4B F8 F8 40 40 $ 1 2 8 . 8 8

222

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 Suppress leading zeros before decimal point zero wages = $.00

223

IBM Mainframe Assembler Language Coding

224

IBM Mainframe Assembler Language Coding


The Translate Instruction
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.

TR

ARGUMENT,TABLE

Before
04 01 03
ARGUMENT

C1 C2 C3 C4 C5 C6 C7
TABLE

After
C5 C2 C4
ARGUMENT

C1 C2 C3 C4 C5 C6 C7
TABLE

225

IBM Mainframe Assembler Language Coding


The Translate Instruction Change ASCII uppercase characters in the input message to their EBCDIC counterparts.
TR TABLE INPUT,TABLE DC DC DC 65XL1'00' C'ABCDEFGHIJKLM' C'NOPQRSTUVWXYZ'

Change EBCDIC uppercase characters in the input message to their lowercase counterparts.
TR INPUT,TABLE2 256AL1(*-TABLE2) TABLE2+C'A' C'abcdefghi' TABLE2+C'J' C'jklmnopqr' TABLE2+C'S' C'stuvwxyz'

TABLE2 DC ORG DC ORG DC ORG DC ORG

226

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. 2. The address of the byte from the first operand that was found to be non-zero in the table is loaded into register 1. 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 CC = 1 CC = 2 CC = 3 All bytes of the 1st operand were found to be zero in the table. A non-zero byte was found in the table before reaching the end of the first operand. The last byte of the first operand was found to be non-zero in the table. Not used. 227

IBM Mainframe Assembler Language Coding


The Translate and Test Instruction (cont.)

TRT

ARGUMENT,TABLE

Before
04 01 03
ARGUMENT

00 C1 00 00 00 00 00
TABLE

00 00 00 00
REG 1

00 00 00 00
REG 2

After
04 01 03
ARGUMENT

00 C1 00 00 00 00 00
TABLE

addr 2nd byte argument

00 00 00 C1
REG 2

REG 1

CC = 1

228

IBM Mainframe Assembler Language Coding


The Translate and Test Instruction (cont.)

TRT

ARGUMENT,TABLE

Before
04 01 03
ARGUMENT

00 00 00 00 00 00 C1
TABLE

00 00 00 00
REG 1

00 00 00 00
REG 2

After
04 01 03
ARGUMENT

00 00 00 00 00 00 C1
TABLE

00 00 00 00
REG 1

00 00 00 00
REG 2

CC = 0

229

IBM Mainframe Assembler Language Coding


The Translate and Test Instruction Table Look for a plus sign (+) in an input line. TRT TABLE3 INPUT,TABLE3 DC ORG DC ORG 256XL1'00' TABLE3+C'+' X'FF'

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. 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 CC = 1 CC = 2 CC = 3 1st and 2nd operand counts are equal 1st operand count low 1st operand count high no movement - destructive overlap - occurs when 1st operand byte is used as a source after data has been moved into it. 231

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 general register specified in the 2nd operand to the memory location designated by bits 8-31 of the general register specified by the 1st operand. This results in a byte-for-byte move. The MVCL requires 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 DC X'40000000' DS CL500

SPACEPAD LONGONE

233

IBM Mainframe Assembler Language Coding


Move Character Long

MVCL

R4,R6

****** BEFORE ******


00 02 08 50 REG 4 Addr. 1st op. 00 00 01 F4 REG 5 Length 1st op.

00 02 08 50 REG 6 Addr. 2nd op.

40 00 00 00 REG 7 Length 2nd op.

****** AFTER ******

00 02 0A 44 REG 4 Addr. 1st op.

00 00 00 00 REG 5 Length 1st op.

00 02 08 50 REG 6 Addr. 2nd op.

40 00 00 00 REG 7 Length 2nd op.

234

IBM Mainframe Assembler Language Coding


Move Character Long Example: Destructive Overlap (Would execute as a MVC instruction.)
LA LA LA L MVCL . . . DS DC DS DS R4,TARGET R5,20 R6,TARGET-10 R7,PADLENTH R4,R6 Rec fld addr Rec fld length Send fld addr Send fld length c.c. = 3

PADLENTH OUTLINE TARGET

OF X'F0000014' CL50 CL50

235

IBM Mainframe Assembler Language Coding


Move Character Long Example: Non-Destructive Overlap
LA LA LA L MVCL . . . DS DC DS DS R4,TARGET-10 R5,20 R6,TARGET R7,PADLENTH R4,R6 Rec fld addr Rec fld length Send fld addr Send fld length c.c. = 0

PADLENTH OUTLINE TARGET

OF X'F0000014' CL50 CL50

236

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


Compare Logical Character Long (cont.)

CLCL

4,2

Before:
00 00 82 5E REG 4 Addr. 1st op. 00 00 53 A2 REG 2 Addr. 2nd op. 00 00 00 0C REG 5 Length 1st op. 40 00 00 09 REG 3 Length 2nd op.

STORAGE:
825E - C1 E2 E8 D3 C4 40 C7 D5 40 E2 F3 F8 53A2 - C1 E2 E8 D3 C4 40 E6 F3 F9

After:
00 00 82 64 REG 4 Addr. 1st op. 00 00 53 A8 REG 2 Addr. 2nd op. 00 00 00 06 REG 5 Length 1st op. 40 00 00 03 REG 3 Length 2nd op.

CC = 1 238

IBM Mainframe Assembler Language Coding


Miscellaneous Directives

Print on Print Off Print Gen -

a program listing will be created (default). no program listing will be created. All statements generated by a macro are printed. No statements generated by a macro are printed (default). Constants are printed in full in the listing. Constants are not printed in full in the listing. Only the first 8 bytes will be printed (default). This suspends the most recently established key words of a print directive. This restores the key words of the most recently suspended print directive. PRINT ON,NOGEN,NODATA

Print Nogen -

Print Data Print Nodata -

Push Print

Pop Print

E.g.

239

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 LA MVI FLTLOOP EQU CLC BE LA BCT B SWITCHON EQU MVI BYPASS EQU . . . FLTTABL EQU TABLNTRY DC DC DC DC DC #ENTRIES EQU . R3,FLTTABL R4,#ENTRIES SWITCH,X'00' * FLTNUM,0(R3) SWITCHON R3,L'TABLNTRY(R3) R4,FLTLOOP BYPASS * SWITCH,X'FF' * SPECIAL FLIGHT TABLE NBR OF ENTRIES IN TABLE RESET SWITCH LOOK FOR SPECIAL FLIGHT YES-GO TURN SWITCH ON NO-POINT TO NEXT TBL ENTRY LOOP BACK NO SPECIAL FLIGHT FOUND FOUND IT

* C'012' C'104' C'255' C'381' C'510' (*-FLTTABL)/L'TABLNTRY

(In a work block - not in the program)


FLTREC FLTNUM DS DS . . . DS 0CL80 CL3

SWITCH

241

IBM Mainframe Assembler Language Coding


Table Search and Program Loop Control Example:
LA LA EQU CLC BE LA BCT B EQU MVC EQU . . R3,FLTTABL POINT TO FLIGHT TABLE R4,NBRNTRYS NBR OF ENTRIES IN TABLE * FLTNBR,0(R3) DO WE HAVE A HIT? PROCESS YES R3,L'FRSTNTRY(R3) NO-POINT TO NEXT ENTRY R4,FLTLOOP LOOP BACK BYPASS * 4(L'PAXNBR,R3),PAXNBR *

FLTLOOP

PROCESS BYPASS

(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

242

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 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)

243

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: 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+
244

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 program, assemble it by using the PARSASM exec. Examine the object code to verify 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.

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 of 27, -9658, and 326. Each one will be 4 bytes long. Use only one data definition instruction for all three.

last updated 02/09/01

245

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 with a value of zero.

10. Define a 132 byte constant consisting of all blanks.

246

IBM Mainframe Assembler Language Coding


Exercise 2 - Move Instructions

For questions 1 - 9, show the contents of the fields requested after the given operation is performed. Each instruction builds on the previous one. 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 JADE OPAL ROCK TOTAL DATA $IS$ DSECT DS DS DS DS DS CSECT USING LA MVC MVC MVC MVC CL4 CL5 CL7 CL4 CL20 DUMMY,R4 R4,EBW000 JADE,JADEC OPAL,OPALC ROCK,ROCKC TOTAL,TOTALC

Follow the above instructions with those in the exercise. Be sure the Define Constants go after all instructions.
JADEC OPALC ROCKC TOTALC DC DC DC DC CL4' ' CL5'STONE' CL7'DIAMOND' ZL4'1234' JADE: JADE: ROCK: ROCK:

1. 2. 3. 4.

MVC MVC MVI MVC

JADE,OPAL JADE+2(2),ROCK+3 ROCK,X'C6' ROCK,OPAL+1

last updated 02/09/01

247

IBM Mainframe Assembler Language Coding


Exercise 2 - Move Instructions (cont.)

5. 6. 7. 8. 9.

MVI MVC MVC

OPAL(2),=C'A' JADE,JADE ROCK-1(2),OPAL+1

OPAL: JADE: OPAL: ROCK: OPAL: JADE:

MVC MVC

OPAL,=X'40' JADE,X'40'

10. Write the code needed to take the 6 bytes that register 3 is pointing to and move them 2 bytes past the address that register 5 is pointing to.

11. Use one MVZ instruction to change the last byte of the value in 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

248

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 FIRST DC SECOND DC THIRD DC FOURTH DC FIFTH DC OF XL8'0000007200000080' H'12' F'100' F'-25' H'16'

1. Put SECOND into register 5 and multiply it by literal 50. 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?

249

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 A. B. 1. OHIO DC MAINE DC OHIO DC MAINE DC OHIO DC MAINE DC OHIO DC MAINE DC OHIO DC MAINE DC OHIO,MAINE BH BL CLEVELAND BANGOR

C'ABC' C'123' X'51' B'01010001' C'121' CL3'$$$' P'25' P'-25' Z'-12' C'-12'

2.

3.

4.

5.

last updated 12/29/99

251

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 together storing the result in table Z. Write this code using a BCT for loop control. Data Definitions: X Y DC DC F'1,2,3,4,5,6,7,8,9,10,11,12' F'1,2,3,4,5,6,7,8,9,10,11,12'

Z DS

12F

252

IBM Mainframe Assembler Language Coding


Exercise 5 - Load and Store

1. 2.

Increment register 3 by 8 without using a storage field. 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.

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.

253

IBM Mainframe Assembler Language Coding

254

IBM Mainframe Assembler Language Coding


Exercise 6 - DSECT

Construct and assemble a DSECT that will consist of the following fields: 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 see the effect a DSECT has on the location counter.

255

IBM Mainframe Assembler Language Coding

256

IBM Mainframe Assembler Language Coding


Exercise 7 - Altering Bits
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 b. OI c. OI d. OI BIN1,BIN2 BIN1,B'00001000' BIN1,B'10000000' 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 b. NI c. NI BIN1,BIN2 BIN1,B'11111110' BIN1,X'80'

257

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.

6. Write the instructions necessary to swap the values of TEMP1 and TEMP2 without using any other storage areas.

258

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'

3.

DP

FIELD1,FIELD2

FIELD1 DC PL7'10005' FIELD2 DC PL3'100'

4.

DP

ABC,DEF

ABC DEF

DC PL2'100' DC PL2'10'

5.

DP

X,Y Y

DC PL5'20245' DC P'25'

259

IBM Mainframe Assembler Language Coding


Exercise 8 - Decimal Arithmetic (cont.)
6.

SP

CHANGE,STORE

CHANGE STORE

DC PL3'60' DC PL1'6'

7.

AP

FIELD1,FIELD2

FIELD1 FIELD2

DC PL7'10005' DC PL3'100'

8. AP

ABC,DEF

ABC DEF

DC PL2'100' DC PL2'10'

9. SP

X,Y

X Y

DC PL5'20245' DC P'25'

260

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 TEMP DC P'125' DISC DC P'120' ZAP TEMP,DISC INFO DC P'1734' LAST DS CL6 UNPK LAST,INFO

INFO

3.

TEMP

4.

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 RATE DC DC CL3'241' CL2'18'

261

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 A. B. C. a. FLDA FLDB FLDA FLDB FLDA FLDB FLDA FLDB FLDA FLDB DC DC DC DC DC DC DC DC DC DC FLDA,FLDB BE BL BH LABEL1 LABEL2 LABEL3

PL15'12' P'16' P'-10652' P'10652' P'-102' X'0000102D' P'1' P'201' P'300' Z'300'

BRANCH

b.

BRANCH

c.

BRANCH

d.

BRANCH

e.

BRANCH

262

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 402020206B2020214B20606060 4020204B202020 5C20206B202020 6020216B202020 40202021 402021204B202040C3D9 4020202020215C RESULT

1. 2. 3. 4. 5. 6. 7.

0010000D 04725C 00056D 00002C 000C 00014C 12001D

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.

263

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. Sample data: 012019034D

264

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.

3. Write a move instruction moving GOAL to TARGET using length attribute (L') rather than the explicit or implicit length.
TARGET GOAL DS DC CL8 XL8'F1F2F3F4F5F6F7F8'

265

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'

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.

266

Das könnte Ihnen auch gefallen