Advertisement
sezenspessa

largest common divisor (hlasm)

May 12th, 2019
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. //DIVIS 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. PRINT ON,NODATA,NOGEN PROGRAM ENTRY BEGIN
  7. DIV CSECT
  8. STM R14,R12,12(R13)
  9. BASR R12,R0 ESTABLISHING ADDRESSABILITY
  10. USING *,R12
  11. ST R13,SAVE+4 STORING CALLERS REGISTERS
  12. LA R13,SAVE I'M PRETTY SURE
  13. **********************************
  14. * START OF PROGRAM *
  15. **********************************
  16. MAIN OPEN (FILEIN,(INPUT)) OPEN INPUT
  17. OPEN (FILEOUT,(OUTPUT)) OPEN OUTPUT
  18. **********************************
  19. * BEGIN MAIN LOOP!! *
  20. **********************************
  21. BEGIN EQU *
  22. GET FILEIN,RECIN
  23. MVC IN1,RECIN GRAB OUR NUMBERS
  24. PACK PD1,NUM1
  25. PACK PD2,NUM2 PACK EM UP
  26. CP PD1,=P'0'
  27. BE ERROR
  28. CP PD2,=P'0'
  29. BE ERROR
  30. **********************************
  31. * MAIN CALCULATIONS *
  32. **********************************
  33. LOOP2 EQU *
  34. ZAP DIV1,PD1
  35. CP PD1,ACC IF ACC IS HIGHER THAN
  36. BL WRITE EITHER NUMBER, THEN WE
  37. CP PD2,ACC ARE CERTAINLY DONE.
  38. BL WRITE
  39. DP DIV1,ACC
  40. CP REM,=P'0'
  41. BE GOOD
  42. AP ACC,=P'1'
  43. B LOOP2
  44. GOOD EQU * JMP HERE IF 1ST NUM...
  45. ZAP DIV1,PD2 IS DIVISIBLE BY ACC
  46. DP DIV1,ACC DIVIDE PD2 BY ACC
  47. CP REM,=P'0'
  48. BE GOOD2 IF BOTH ARE DIVISIBLE BY ACC
  49. AP ACC,=P'1' IF ONLY THE FIRST IS
  50. B LOOP2
  51. GOOD2 EQU * BOTH NUMBERS DIVISIBLE
  52. ZAP GACC,ACC BY ACC.
  53. AP ACC,=P'1' ADDING ONE TWO ACCUMULATOR
  54. B LOOP2 BACK TO MAIN LOOP
  55. **************************
  56. * OUTPUT MESSAGE *
  57. **************************
  58. WRITE EQU *
  59. MVC OUTDV1,EDWD PACKED DEC -> CHARACTER
  60. ED OUTDV1,PD1
  61. MVC OUTDV2,EDWD
  62. ED OUTDV2,PD2
  63. MVC OUTDV3,EDWD
  64. ED OUTDV3,GACC
  65. PUT FILEOUT,OUTMSG WRITE OUR MESSAGE
  66. ZAP ACC,=P'2' RESET OUR ACCUMULATOR
  67. ZAP GACC,=P'0' RESET BEST KNOWN DIVISOR
  68. B BEGIN BACK TO THE BEGINNING!
  69. FINISH EQU *
  70. CLOSE FILEIN CLOSE FILES
  71. CLOSE FILEOUT
  72. ******** EXIT ********
  73. L R13,SAVE+4 RETURN REGISTERS
  74. LM R14,R12,12(R13)
  75. LA R15,0
  76. BR R14 RETURN TO OS
  77. ERROR EQU *
  78. PUT FILEOUT,=CL80'NO DIVISION BY 0.'
  79. B FINISH
  80. *********************************
  81. * INPUT FILE *
  82. **********************************
  83. FILEIN DCB DSORG=PS,MACRF=(GM),DDNAME=FILEIN,EODAD=FINISH, X
  84. RECFM=FB,LRECL=80
  85. RECIN DS CL80
  86. *********************************
  87. * OUTPUT FILE *
  88. *********************************
  89. FILEOUT DCB DSORG=PS,MACRF=(PM),DDNAME=FILEOUT,RECFM=FB,LRECL=80
  90. *
  91. LTORG
  92. ACC DC PL3'1' ACCUMULATOR, START @ 1
  93. GACC DC PL3'0' OUR BEST-KNOWN DIVISOR
  94. EDWD DC X'2020202021' EDIT WORD
  95. *
  96. IN1 DS CL80 REDUNDANT TO 'RECIN'
  97. HPD1 DS PL3 BUT IT'S EASIER FOR ME
  98. HPD2 DS PL3 TO TRACK IN MY HEAD
  99. ORG IN1
  100. NUM1 DS CL3 OUR NUMBER WE GRAB FROM
  101. SPACES DS CL1 THE FILE.
  102. NUM2 DS CL3
  103. ORG ,
  104. *
  105. DIV2 DS PL3
  106. DIV1 DS PL7 OUR MAIN DIVISION AREA
  107. ORG DIV1
  108. QUOT DS PL4 QUOTIENT
  109. REM DS PL3 REMAINDER
  110. ORG ,
  111. BLANKS DS CL70' '
  112. *
  113. PD1 DS PL2 OUR FIRST NUMBER (PD)
  114. PD2 DS PL2 OUR SECOND NUMBER (PD)
  115. *******************************
  116. * OUTPUT MESSAGE *
  117. *******************************
  118. OUTMSG DS CL80
  119. ORG OUTMSG
  120. MSG1 DC CL13'1ST NUMBER: '
  121. OUTDV1 DS CL3 PD1
  122. SPACE1 DC CL2' '
  123. MSG2 DC CL13'2ND NUMBER: '
  124. OUTDV2 DS CL3 PD2
  125. SPACE2 DC CL2' '
  126. MSG3 DC CL21'GREATEST DIVISOR: '
  127. OUTDV3 DS CL8 GACC
  128. ORG ,
  129. *******************************
  130. * REGISTERS *
  131. *******************************
  132. SAVE DS 18F
  133. R0 EQU 0
  134. R1 EQU 1
  135. R2 EQU 2
  136. R3 EQU 3
  137. R4 EQU 4
  138. R5 EQU 5
  139. R6 EQU 6
  140. R7 EQU 7
  141. R8 EQU 8
  142. R9 EQU 9
  143. R10 EQU 10
  144. R11 EQU 11
  145. R12 EQU 12
  146. R13 EQU 13
  147. R14 EQU 14
  148. R15 EQU 15
  149. END DIV
  150. /*
  151. //G.SYSUDUMP DD SYSOUT=*
  152. //G.FILEOUT DD SYSOUT=*
  153. //SETVAR SET REGS=&SYSUID..TEST(REGS)
  154. //G.REGS DD DSN=&REGS,DISP=SHR
  155. //G.FILEIN DD *
  156. 250 750
  157. 020 030
  158. 045 025
  159. 959 343
  160. 004 444
  161. 000 343
  162. /*
  163. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement