;DAT領域のデータをビット列逆転、語順逆転してREVBITに格納する
;「アセンブラ言語 CASLII」東田、山本、広瀬著　工学図書（株）
;１８０ー１８４頁のコードを元にして改造作成したものです。
MAIN	START
	LAD 	GR1,DAT
	LAD	GR5,REVBIT
	LD	GR0,N
	CALL 	REVERSN
	;ST	GR0,REVBIT
	RET
DAT	DC 	#9368, #7E25,#EFF3
	DC	17159,-7919,+35012
REVBIT	DS	6;4;3;5
N	DC	6;4;3;5 ;語数
	END
;--------------
REVERSN	START
	PUSH	0,GR1
	PUSH	0,GR2
	PUSH	0,GR5
	PUSH	0,GR6
	LAD	GR2,-1,GR1 ;
	LAD	GR6,-1,GR5
	ADDA	GR2,GR0
	ADDA	GR6,GR0
LP	LD	GR0,0,GR1 ;初めの語
	CALL	REVERS
	ST	GR0,WORK1
	LD	GR0,0,GR2 ;後ろの語
	CALL 	REVERS
	;ST 	GR0,0,GR1
	ST	GR0,0,GR5
	LD 	GR0,WORK1
	;ST	GR0,0,GR2
	ST	GR0,0,GR6
	LAD	GR1,1,GR1
	LAD	GR5,1,GR5
	LAD	GR2,-1,GR2
	LAD	GR6,-1,GR6
	CPA	GR2,GR1
	JPL	LP
	JZE	LP
	POP	GR6
	POP	GR5
	POP	GR2
	POP	GR1
	RET
WORK1	DS	1
	END
;--------------------------------------
REVERS	START
	PUSH	0,GR1
	PUSH	0,GR2
	LD	GR1,GR0
	LAD	GR2,16 ;loop counter
	LAD	GR0,0
	CPA	GR1,=0
LOOP	JZE	FIN
	JPL	OFF
	OR	GR0,=#8000
OFF	SUBA	GR2,=1
	JZE	FIN1
	SRL	GR0,1
	SLL	GR1,1
	JUMP 	LOOP
FIN	SRL	GR0,-1,GR2 ;未処理ビット数だけシフト
FIN1	POP	GR2
	POP	GR1
	RET
	END
;--------------
; Type your source code in lowercase, and then,
; press Ctrl+Shift+O at the same time, it will
; convert all the characters to upper case.
; This conversion might exclude character constants, such as DC 'sum is '.
; Ctrl+Shift+L converts all the characters to upper case in a line
;        with a blinking underline of the cursor.
;-----------------------
