Advertisement
sezenspessa

real number (float) division (HLASM)

Aug 4th, 2019
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 KB | None | 0 0
  1. //DIVDEC JOB 'SEZEN',CLASS=A,NOTIFY=&SYSUID,MSGCLASS=H,
  2. // MSGLEVEL=(1,1)
  3. // EXEC ASMACLG
  4. //C.SYSOUT DD SYSOUT=*
  5. //C.SYSIN DD *
  6. **********************************
  7. * DOES PACKED DECIMAL MATH ON *
  8. * A CHARACTER WHICH ... *
  9. * HAS A DECIMAL PLACE IN IT... *
  10. * PACKING A CHARACTER RESULTS IN *
  11. * 22.22 -> 22B22F WHICH IS BAD *
  12. * AND ANNOYING, SO WE EXTRACT *
  13. * THE NUMBERS AND DECIMALS THEN *
  14. * OVERWRITE THE DECIMAL PLACE *
  15. **********************************
  16. PRINT ON,NODATA,NOGEN PROGRAM ENTRY BEGIN
  17. DIV CSECT
  18. STM R14,R12,12(R13)
  19. BASR R12,R0 ESTABLISHING ADDRESSABILITY
  20. USING *,R12
  21. ST R13,SAVE+4 STORING CALLERS REGISTERS
  22. LA R13,SAVE
  23. **********************************
  24. * START OF PROGRAM *
  25. **********************************
  26. MAIN OPEN (FILEIN,(INPUT)) OPEN INPUT
  27. OPEN (FILEOUT,(OUTPUT)) OPEN OUTPUT
  28. **********************************
  29. * BEGIN MAIN LOOP!! *
  30. **********************************
  31. BEGIN EQU *
  32. GET FILEIN,NUMS GET NUMBERS
  33. * PACK
  34. MVC DEC1,PART12
  35. PACK PD1,FLOAT1 PACK OUR CHARACTERS
  36. MVC DEC2,PART22 DECIMAL IGNORED, I.E.
  37. PACK PD2,FLOAT2 [22].[22] = 2222 AS WE
  38. MVC DEC3,PART32 OVERWRITE DECIMAL CHAR
  39. MVC OUTDV1,DEC3 THUS ADDRS END AS 2222
  40. PUT FILEOUT,OUTDV1
  41. PACK PD3,FLOAT3
  42. * TEST
  43. AP TEST1,PD1 TESTING VALIDITY OF OUR PD'S
  44. PUT FILEOUT,=CL80'ADDED 1'
  45. AP TEST2,PD2
  46. PUT FILEOUT,=CL80'ADDED 2'
  47. AP TEST3,PD3
  48. PUT FILEOUT,=CL80'ADDED 3'
  49. * MATH
  50. ZAP AD1,PD1 MOVE PD1 IN PREPARATION
  51. SRP PD2,64-1,0 SHIFT PD2 RIGHT, RESULT=3.33
  52. AP AD1,PD2 ADD PD1 + PD2
  53. SRP PD3,64-2,0 SHIFT PD3 RIGHT, RESULT=4.44
  54. ZAP DD1,AD1 MOVE AD1 INTO DD1 (DIVIDEND)
  55. DP DD1,PD3 DIVIDE AD1 BY PD3
  56. ZAP DD2,REM GETTING THE SECOND DECIMAL
  57. ZAP PD32,PD3 MOVE DIVISOR TO ANOTHER ADDR
  58. SRP PD32,64-1,0 SHIFT DIVISOR GIVING .444
  59. DP DD2,PD32 DIVIDE 3.35 BY .444 GIVING
  60. * OUTPUT 7
  61. MVC OUTDV1,EDWD1
  62. ED OUTDV1,PD1 START EDITING RESULTS
  63. MVC OUTDV2,EDWD1 TO BE OUTPUTTED...
  64. ED OUTDV2,PD2
  65. MVC OUTDV3,EDWD1
  66. ED OUTDV3,PD3
  67. MVC OUTDV4,EDWD1
  68. ED OUTDV4,AD1
  69. MVC QUOT1,EDWDQ
  70. ED QUOT1,QUOT
  71. MVC QUOT2,EDWDQ
  72. ED QUOT2,QUOTA
  73. PUT FILEOUT,OUTMSG OUTPUT OUR MSG
  74. **********************************
  75. * FINISH PROGRAM *
  76. **********************************
  77. FINISH EQU *
  78. CLOSE FILEIN CLOSE FILES
  79. CLOSE FILEOUT
  80. L R13,SAVE+4 RETURN REGISTERS
  81. LM R14,R12,12(R13)
  82. LA R15,0
  83. BR R14 RETURN TO OS
  84. **********************************
  85. * INPUT FILE *
  86. **********************************
  87. FILEIN DCB DSORG=PS,MACRF=(GM),DDNAME=FILEIN,EODAD=FINISH, X
  88. RECFM=FB,LRECL=80
  89. RECIN DS CL80
  90. **********************************
  91. * OUTPUT FILE *
  92. **********************************
  93. FILEOUT DCB DSORG=PS,MACRF=(PM),DDNAME=FILEOUT,RECFM=FB,LRECL=80
  94. SAVE DS 18F
  95. LTORG
  96. *********************
  97. * PACKED DECIMALS *
  98. *********************
  99. PD1 DS PL3 PACKED DECIMALS...
  100. PD2 DS PL3
  101. PD3 DS PL3
  102. PD32 DS PL3
  103. AD1 DS PL3
  104. *********************
  105. * DIVISION AREA *
  106. *********************
  107. DD1 DS PL5
  108. ORG DD1
  109. QUOT DS PL2 QUOTENT #1
  110. REM DS PL3 REMAINDER #1
  111. OUT ,
  112. DD2 DS PL5 DIVISION AREA FOR DECIMAL
  113. ORG DD2 OF DIVISION AREA 1'S QUOT
  114. QUOTA DS PL2
  115. REMA DS PL3
  116. ORG ,
  117. *********************
  118. * OUTPUT MESSAGE *
  119. *********************
  120. OUTMSG DS CL80 OUT MSG
  121. ORG OUTMSG
  122. OUTDV1 DS CL6 OUTPUT IS:
  123. DC CL2' ' 1ST INPUT
  124. OUTDV2 DS CL6 2ND INPUT
  125. DC CL2' ' 3RD INPUT
  126. OUTDV3 DS CL6 1ST + 2ND
  127. DC CL2' ' (1ST + 2ND) / 3RD
  128. OUTDV4 DS CL6
  129. DC CL2' '
  130. OUTDV5 DS CL5
  131. ORG OUTDV5
  132. QUOT1 DS CL3
  133. DC CL1'.'
  134. QUOT2 DS CL3
  135. ORG , EDIT
  136. *******************
  137. * EDIT WORDS *
  138. *******************
  139. EDWD1 DC X'2020204B2020' EDIT WORD FOR INPUTS N OUT
  140. EDWDQ DC X'202120' EDIT WORD FOR QUOTENTS
  141. *******************
  142. * INPUTS *
  143. *******************
  144. NUMS DS CL80 OUR INPUTS
  145. ORG NUMS
  146. *******************
  147. * 1ST INPUT *
  148. *******************
  149. FLOAT1 DS CL4 INPUT 1
  150. ORG FLOAT1
  151. PART11 DS CL2 1ST HALF OF NUMBER
  152. DEC1 DS CL1 DECIMAL (IS OVERWRITTEN)
  153. PART12 DS CL2 2ND HALF OF NUMBER
  154. *******************
  155. * 2ND INPUT *
  156. *******************
  157. FLOAT2 DS CL4
  158. ORG FLOAT2 INPUT 2...
  159. PART21 DS CL1
  160. DEC2 DS CL1 ETC. ETC.
  161. PART22 DS CL3
  162. *******************
  163. * 3RD INPUT *
  164. *******************
  165. FLOAT3 DS CL5 INPUT 3......
  166. ORG FLOAT3
  167. PART31 DS CL1
  168. DEC3 DS CL1
  169. PART32 DS CL4
  170. ORG ,
  171. TEST1 DC PL4'0' OUR ADDR'S WE USE TO TEST
  172. TEST2 DC PL4'0' IF OUR CONVERTED PD'S
  173. TEST3 DC PL3'0' ARE VALID OR NOT
  174. ORG ,
  175. ************************
  176. * REGISTERS *
  177. ************************
  178. R0 EQU 0 REGISTERS
  179. R1 EQU 1
  180. R2 EQU 2
  181. R3 EQU 3
  182. R4 EQU 4
  183. R5 EQU 5
  184. R6 EQU 6
  185. R7 EQU 7
  186. R8 EQU 8
  187. R9 EQU 9
  188. R10 EQU 10
  189. R11 EQU 11
  190. R12 EQU 12
  191. R13 EQU 13
  192. R14 EQU 14
  193. R15 EQU 15
  194. END DIV
  195. /*
  196. //G.SYSUDUMP DD SYSOUT=*
  197. //G.FILEOUT DD SYSOUT=*
  198. //G.FILEIN DD *
  199. 22.223.3334.4444
  200. /*
  201. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement