Google
 

Trailing-Edge - PDP-10 Archives - BB-H138E-BM - 6-1-sources/cpymem.mac
There are 11 other files named cpymem.mac in the archive. Click here to see a list.
	TITLE	CPYMEM - COPY MEMORY


; IDENT 1-001

;AUTHOR : GRAHAM BEECH	CREATION DATE : 01-MAR-1983

;****************************************************************************
;*									    *
;*  COPYRIGHT (C) 1978, 1985                                                *
;*  BY DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.			    *
;*  ALL RIGHTS RESERVED.                                                    *
;* 									    *
;*  THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED  *
;*  ONLY  IN  ACCORDANCE  WITH  THE  TERMS  OF  SUCH  LICENSE AND WITH THE  *
;*  INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR  ANY  OTHER  *
;*  COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY  *
;*  OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY  *
;*  TRANSFERRED.							    *
;* 									    *
;*  THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE  WITHOUT  NOTICE  *
;*  AND  SHOULD  NOT  BE  CONSTRUED  AS  A COMMITMENT BY DIGITAL EQUIPMENT  *
;*  CORPORATION.							    *
;* 									    *
;*  DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR  RELIABILITY  OF  ITS  *
;*  SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.		    *
;*									    *
;****************************************************************************

;
;FACILITY:	EDT VERSION 3
;

;FUNCTIONAL DESCRIPTION:
;
; 	THIS MODULE CONTAINS ROUTINES TO COPY A NUMBER OF WORDS
;	OR A NUMBER OF BYTES. IF THE SOURCE AND DESTINATION OVERLAP
;	THEN THE ROUTINES ENSURE THAT THE COPY IS DONE CORRECTLY.
;
;MODIFIED BY:
;
; 1-001	ORIGINAL.  GB 01-Mar-1983
; 1-002 - Fix to prevent EDT's high-seg becoming private. CJG 21-Dec-1983
;--

	PAGE
	TWOSEG
	RELOC	400000

	SEARCH	MONSYM
	SEARCH	MACSYM

	INTERN	CPYMEM,CPYSTR

	T1=1
	T2=2
	T3=3
	T4=4
	T5=5
	T6=6
	P=17

;
; COPY A NUMBER OF WORDS FROM ONE LOCATION TO ANOTHER
; THE COPY IS DONE FORWARD OR IN REVERSE DEPENDING THE 
; ADDRESSES OF THE SOURCE AND DESTINATION IN CASE THEY
; OVERLAP.
;
;CALLED WITH FOLLOWING ARGS ON STACK
;	# WORDS TO COPY
;	SOURCE ADDRESS
;	DESTINATION ADDRESS
;

CPYMEM::
	MOVE	T1,-3(P)		;Get no. words to copy
	JUMPE	T1,CPY002		;Return if zero
	MOVE	T2,-2(P)		;Get the source address
	MOVE	T3,-1(P)		; and Destination
	HRRI	T1,-1(T1)		;Make a count - 1
	CAIL	T2,(T3)			;Source > Destination?
	JRST	CPY001			;Yes - start at top
;
; DO COPY FROM BOTTOM UP
;
	HRLI	T1,(T1)			;Count into left half
	TLO	T1,400000		;Make it negative for JUMPL
	ADDI	T1,(T2)			;Count,,address
	SUBI	T3,(T2)			;Destination - Source
	JUMPE	T3,CPY002		;Return now if dest=source
	MOVSI	T4,(POP T1,(T1))
	HRRM	T3,T4			;Modify POP
	XCT	T4			;Copy the required no. of words
	JUMPGE	T1,CPY002		;...
	JRST	.-2			;;Loop....
;
; DO COPY TOP DOWN
;
CPY001:	CAIN	T2,(T3)			;Don't copy if dest=source
	JRST	CPY002			;...
	ADDI	T1,(T3)			;Last word to copy
	HRLI	T3,(T2)			;Source,,Destination
	BLT	T3,(T1)			;Do the copy
CPY002:	RET

	PAGE
; COPY A STRING FROM ONE LOCATION TO ANOTHER
; THE SOURCE AND DESTINATION MAY OVERLAP
;
;CALLED WITH FOLLOWING ARGS ON STACK
;	# BYTES TO COPY
;	SOURCE BYTE PTR
;	DESTINATION BYTE PTR
;


CPYSTR::
	MOVE	T1,-3(P)		;Get no. bytes to copy
	JUMPE	T1,CPYST3		;Return if zero
	MOVE	T2,-2(P)		;Get the source ptr
	MOVE	T3,-1(P)		; and Destination ptr
	PUSH	P,T4			;Preserve important
	PUSH	P,T5			; acc's...
	PUSH	P,T6			;...
	TLNE	T2,-1			;Check for illegal arg
	TLNN	T3,-1			;...
	JRST	CPYST4			;...
	CAIN	T1,1			;If 1 byte just do it
	JRST	CPYST1			;...
	HRRZI	T4,(T2)			;Get address only
	CAILE	T4,(T3)			;Source > Destination
	JRST	CPYST1			;Yes - copy top down
	CAIE	T4,(T3)			;No. Equal ?
	JRST	CPYST0			;No. Copy bottom up
	LDB	T4,[POINT 6,T2,5]	;Get source position
	LDB	T5,[POINT 6,T3,5]	;Get destination position
	CAIGE	T4,(T5)			;Source > Destination
	JRST	CPYST1			;Yes - copy top down
	CAIN	T4,(T5)			;Same ?
	JRST	CPYST2			;Yes - nothing to do

;
; COPY FROM BOTTOM UP
;
CPYST0:
	MOVEI	T4,(T1)			;Point to end
	ADJBP	T4,T2			;..of source
	MOVE	T2,T4			;..
	MOVEI	T4,(T1)			;..and destination
	ADJBP	T4,T3			;..
	MOVE	T3,T4			;..
CPY:	LDB	T4,T2			;Copy the string
	DPB	T4,T3			; a byte at a time
	SETO	T4,			;Back up source a byte
	ADJBP	T4,T2			;...
	MOVE	T2,T4			;Copy B.P.
	SETO	T4,			;Back up dest a byte
	ADJBP	T4,T3			;...
	MOVE	T3,T4			;Copy B.P.
	SOJG	T1,CPY			;Loop ...
	JRST	CPYST2
;
; COPY FROM TOP DOWN
;
CPYST1:	MOVE	T5,T3			;Setup BP's
	SETZB	T3,T6			;...
	MOVE	T4,T1			;Copy no. bytes
	EXTEND	T1,[MOVSLJ]		;Copy the string
	JFCL

CPYST2:	POP	P,T6			;Restore Ac's
	POP	P,T5			;...
	POP	P,T4			;...
CPYST3:	RET

CPYST4: HALT	.
	JRST	CPYST2

	END