;2015H25秋試験プログラム２
;---------------------------
MAIN START
	LD GR0,X
	LAD GR1,Y
	LD GR2,M
	LAD GR3,Z
	LD GR4,N
	CALL BITINSL
	RET
X DC #5E96
Y DS 5
Z DS 6
M DC 36
N DC 10
	END
;-----------------------
BITINSL START
	RPUSH
LOOP1 CPA GR2,=17
	JMI INS
	CALL COPY
	SUBA GR2,=16
	JUMP LOOP1
INS CALL BITINS
	LAD GR1,1,GR1
	LAD GR3,2,GR3
	SUBA GR4,=1
	JZE FIN
LOOP2 CALL COPY
	JNZ LOOP2
FIN RPOP
	RET
;ビット列 Y の1語を結果の領域へコピー
COPY LD GR5,0,GR1
	ST GR5,0,GR3
	LAD GR1,1,GR1
	LAD GR3,1,GR3
	SUBA GR4,=1
	RET
	END
;---------------------------
BITINS START
	RPUSH
	LD GR6,=16
	SUBA GR6,GR2
	LD GR1,0,GR1
	LD GR4,GR1
	LD GR5,GR0
	SRL GR1,0,GR6
	SLL GR1,0,GR6
	SLL GR4,0,GR2
	SRL GR4,0,GR2
	SRL GR0,0,GR2
	SLL GR5,0,GR6
	OR GR1,GR0
	OR GR4,GR5
	ST GR1,0,GR3
	ST GR4,1,GR3
	RPOP
	RET
	END
;----------------------------