IBM System Z汇编程序-56个字节。
(96个字节源的。此前712个 384 202字节源的,168字节可执行文件)。
较小的版本。不再保存调用者的寄存器,更改为文字存储,更改寻址方式。
l CSECT
using l,15
l 5,y
n 5,f
bnz r
xr 4,4
l 5,y
d 4,c
ch 4,i
bne i
n 5,f
bnz r
i dc h'0'
r b *
y dc f'2004'
f dc f'3'
c dc f'100'
end
新版本。如果是a年,它将与S0C1结合使用,如果不是,则循环。希望能满足指示结果的要求。
l CSECT
ASMDREG
SYSSTATE archlvl=2
IEABRCX DEFINE
save (14,12)
larl r9,s
using s,r9
st 13,w+4
la 13,w
st 13,w+8
la 5,2004
st 5,y
n 5,=f'3'
bnz r
xr r4,r4
l 5,y
d r4,=f'100'
ch r4,=h'0'
bne i
n 5,=f'3'
bnz r
i dc h'0'
r b 0
s dc 0d'0'
y ds f
w ds 18f
ltorg
end
好的,所以不是最短的(尽管可能只有一次,我们查看实际执行的代码加上解释器的大小...)
leapyear CSECT
ASMDREG
SYSSTATE archlvl=2
IEABRCX DEFINE
save (14,12)
larl r9,staticArea
using staticArea,r9
st r13,w_savea+4 .Save callers savearea
la r13,w_savea .Address my savearea
st r13,w_savea+8 . and save it
open (O,OUTPUT) .open file
la r5,1936 .r5 = input year
st r5,years .Save year
cvd r5,double .Convert year to p-decimal
mvc edarea,=xl8'4020202020202120' .Move in edit mask
ed edarea,double+4 .Make packed decimal year printable
mvc outrec(4),edarea+4 .Move year string to output area
bas r10,isitleap .Call leap year routine
close (O) .Close files
b return .Branch to finish
isitleap ds 0h
mvi outrec+5,c'N' .Set default value
n r5,=f'3' .Are last 2 bits 0 (Divisible by 4)?
bnz notleap .No - not leap
xr r4,r4 .Clear R4
l r5,years .Reload r5 with year
d r4,=f'100' .divide r4/r5 pair by 100
ch r4,=h'0' .Remainder 0?
bne isleap .No - leap year
n r5,=f'3' .Quotient divisible by 4?
bnz notleap .No - not leap
isleap ds 0h
mvi outrec+5,c'Y' .Move in leap year indicator
notleap ds 0h
put O,outrec .Print output record
br r10 .Return to caller
* Program termination
return ds 0h
l r13,w_savea+4 .Restore callers savearea
return (14,12),,rc=0 .Restore registers and return
* storage areas
staticarea dc 0d'0'
outrec ds cl10
years ds f
w_savea ds 18f save area
edarea ds cl8 .edit area
double ds d
* Macros and literals
print nogen
O dcb recfm=F,lrecl=6,dsorg=PS,ddname=O,macrf=PM
print gen
*
ltorg literal storage
end
输出:
如果不是,则将S0C1终止为a年,否则为S222(CPU时间用尽时)。
1936是1805 N 1900 N 2272是2400 Y
(多次运行时)
(divisible by 4)∧((divisible by 100)→(divisible by 400))
。