summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/FC/MOVE.ASM
blob: d40e5d6542efce0aff74d7b0b725c5a1c0158ade (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
;
; memory routines
;

.xlist
include	version.inc
include cmacros.inc
.list

sBegin	code
assumes cs,code

cProc	Move,<PUBLIC>,<DS,SI,DI>
parmD	src
parmD	dst
parmW	count
cBegin
	mov	cx,count
	jcxz	NoByte			; No characters to move
	les	di,dst			; grab pointers
	lds	si,src
	cld
	mov	ax,ds
	cmp	ax,Seg_dst
	jnz	SimpleMove		; segments are NOT the same, no opt
	cmp	si,di			; is the start of source before dest
	jb	TestMove		; yes, try to optimize

SimpleMove:
	shr	cx,1
	rep	movsw
	jnc	NoByte
	movsb
	jmp	short NoByte

TestMove:
	mov	ax,di
	sub	ax,si			; ax = difference between regions
	cmp	ax,cx			; is difference greater than region?
	jae	SimpleMove		; yes, no optimize
	mov	ax,cx			; optimize by copying down from top
	dec	ax
	add	di,ax
	add	si,ax
	std
	rep	movsb			; no word optimization here

NoByte:
	cld
cEnd

cProc	Fill,<PUBLIC>,<DI>
parmD	dst
parmB	value
parmW	count
cBegin
	cld
	les	di,dst
	mov	al,value
	mov	ah,value
	mov	cx,count
	shr	cx,1
	jcxz	fill1
	rep	stosw
fill1:
	jnc	fill2
	stosb
fill2:
cEnd

sEnd

end