.TITLE	STDIMB - STD IBM data conversion routines
.IDENT	/1-003/	
;+
;
; OWN STORAGE:
;
	.PSECT	_STD_DATA	PIC,USR,CON,REL,LCL,NOSHR,NOEXE,RD,WRT,LONG

; 
; PSECT DECLARATIONS
;
	.PSECT	_STD_CODE	PIC,USR,CON,REL,LCL,SHR,EXE,RD,NOWRT,LONG
	.SBTTL	STD_SWAP_BYTES - Swap bytes
;++
; FUNCTIONAL DESCRIPTION:
;
;	This procedure is used to swap the bytes of an array of 16 bit
;	words.  The swapping is done in place in the array proviede by
;	the caller.
;
; CALLING SEQUENCE:
;
;	CALL STD_SWAP_BYTES(length.rw.r,array.mw.ra)
;
; FORMAL PARAMETERS:
;
;	LENGTH	Number of 16 bit words in ARRAY
;	ARRAY	Word array to have bytes swapped
;
;--
	.PSECT	_STD_CODE
LENGTH	=4	;Offset from AP of length address
ARRAY	=8	;Offset from AP of array address

	.ENTRY	STD_SWAP_BYTES,^M<R2>
	MOVL	@LENGTH(AP),R1		; Get number of words in array.
	BEQL	20$			; Done if zero.
	MOVL	ARRAY(AP),R0		; Get address of array.
10$:	MOVB	1(R0),R2		; Save second byte.
	MOVB	(R0),1(R0)		; Move first byte to second.
	MOVB	R2,(R0)			; Move second byte to first.
	ADDL2	#2,R0			; Point to next word.
	SOBGTR	R1,10$			; Loop until done.
20$:	RET				; Return to caller

	.SBTTL	STD_SWAP_WORDS - Swap words
;++
; FUNCTIONAL DESCRIPTION:
;
;	This procedure is used to swap the words of an array of 32 bit
;	longwords.  The swapping is done in place in the array proviede by
;	the caller.
;
; CALLING SEQUENCE:
;
;	CALL STD_SWAP_WORDS(length.rw.r,array.mw.ra)
;
; FORMAL PARAMETERS:
;
;	LENGTH	Number of 32 bit longwords in ARRAY
;	ARRAY	Word array to have bytes swapped
;--
	.PSECT	_STD_CODE
LENGTH	=4	;Offset from AP of length address
ARRAY	=8	;Offset from AP of array address

	.ENTRY	STD_SWAP_WORDS,^M<R2>
	MOVL	@LENGTH(AP),R1		; Get number of longwords in array.
	BEQL	20$			; Done if zero.
	MOVL	ARRAY(AP),R0		; Get address of array.
10$:	MOVW	2(R0),R2		; Save second word.
	MOVW	(R0),2(R0)		; Move first word to second.
	MOVW	R2,(R0)			; Move second word to first.
	ADDL2	#4,R0			; Point to next longword.
	SOBGTR	R1,10$			; Loop until done.
20$:	RET				; Return to caller

	.END
