IBM Assembly Language Coding (ALC) Part 4
IBM Assembly Language Coding (ALC) Part 4
IBM Assembly Language Coding (ALC) Part 4
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
212
213
X'21'
digit
214
PATTERN FC DS DS DS SS DS 4B DS DS
215
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
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
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
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
2.
220
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
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
223
224
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
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'
226
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
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
00 00 00 C1
REG 2
REG 1
CC = 1
228
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
230
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
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
SPACEPAD LONGONE
233
MVCL
R4,R6
234
235
236
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
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
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 -
Push Print
Pop Print
E.g.
239
240
SWITCH
241
FLTLOOP
PROCESS BYPASS
242
243
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
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.
4. Define a binary constant with a value of hex C4. Use implied length.
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.
245
9. Define eight zoned decimal constants, each of them 3 bytes long with a value of zero.
246
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.
247
5. 6. 7. 8. 9.
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
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
250
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.
251
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
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.
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.
8.
253
254
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
256
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
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
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
4.
DP
ABC,DEF
ABC DEF
DC PL2'100' DC PL2'10'
5.
DP
X,Y Y
DC PL5'20245' DC P'25'
259
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
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
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
1. 2. 3. 4. 5. 6. 7.
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
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
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
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