1 
 2 " roundb --- round given integer to next higher binary multiple
 3 
 4 " ans = roundb(num, i)
 5 
 6           name      roundb
 7 
 8           entry     roundb
 9           entry     roundb36
10 
11           entry     rndshftb            Round, then shift
12           entry     rndshftb36                    Round to 36, then binary power, then shift
13 
14           equ       temploc,22          Use location in caller's stack frame(MM callout space)
15 
16 roundb:   eax0      0                   Entry for rounding only
17           tra       roundbx             ..
18 
19 roundb36: eax0      1                   Round to 36, then to binary power
20 
21 roundbx:  eax1      0                   Mask after shift
22           tra       join                ..
23 
24 rndshftb: eax0      0                   Set for shift and round
25           tra       rndshftbx           ..
26 
27 rndshftb36:
28           eax0      1                   Divide by 36 first, then round, then shift
29 rndshftbx:
30           eax1      1                   Set for shifts
31 
32 join:     eaa       0                   Clear A
33           lcq       1,dl                All 1-s to Q
34 
35           lxl7      ap|4,*              Pick up shift value
36           cmpx7     35,du               Check range
37           trc       retlarge            Give largest positive value for out-of-bound shift value
38 
39           lls       0,7                 Form carry field and mask simultaneously
40           staq      sp|temploc          Save value for later
41           cmpx0     0,du                See if first divide by 36
42           tnz       div36               ..
43           ada       ap|2,*              Damn the overflow, he deserves it!
44 mask:     xec       post_op,1           Shift or mask
45 
46 ret:      sta       ap|6,*              Give answer
47 
48           lpri      sp|0                Short return
49           lreg      sp|8                ..
50           rtcd      sp|20               ..
51 
52 div36:    ldq       ap|2,*              Get value
53           adq       35,dl               Add 35 for rounding
54           div       36,dl               Divide
55           lls       36                  Move to A
56           ada       sp|temploc          Add in binary field
57           tra       mask                ..
58 
59 retlarge: lls       35                  Use generated mask for answer
60           tra       ret                 Give back 377...
61 
62 post_op:  ana       sp|temploc+1        Mask out low order bits
63           arl       0,7                 Shift value
64 
65           end
66 ^@