-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort.X68
81 lines (78 loc) · 1.58 KB
/
sort.X68
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
74
75
76
77
78
79
80
81
*-----------------------------------------------------------
* Program :
* Written by :
* Date :
* Description:
*-----------------------------------------------------------
ORG $1000
START: ; first instruction of program
MOVE.B #50,D0
TRAP #15 ; initialize fileio
MOVE.L #INFILE,A1
MOVE.B #51,D0
TRAP #15 ; open file
MOVE.L LENGTH,D2
MOVE.L #BUFFER,A1
MOVE.B #53,D0
TRAP #15 ; read file
MOVE.B #56,D0
TRAP #15 ; close file
MOVE.L D2,-(sp)
JSR SORT ; call swap
MOVE.L #OUTFILE,A1
MOVE.B #52,D0
TRAP #15 ; open output file
MOVE.L #BUFFER,A1
MOVE.B #54,D0
TRAP #15 ; write file
MOVE.B #56,D0
TRAP #15 ; close file
MOVE.B #9,D0
TRAP #15 ; halt simulator
SORT: MOVE.L D2,-(sp) ; implements bubble sort
MOVE.L 8(sp),D2
MOVE.L D0,-(sp)
MOVE.L D1,-(sp)
MOVE.B D3,-(sp)
MOVE.B D4,-(sp)
MOVE.L A0,-(sp)
MOVE.L A1,-(sp)
RESORT: MOVE.L #BUFFER,A0
MOVE.L #BUFFER,A1
ADD.L #1,A1
MOVE.L #2,D0 ; initalize loop ctr
MOVE.L #0,D1 ; initalize nswaps
LOOP: CMP.L D2,D0
BGT DONE
MOVE.B (A0),D3
MOVE.B (A1),D4
CMP.B D4,D3
BLE NOSWAP
ADDQ.L #1,D1
MOVE.B D3,(A1)
MOVE.B D4,(A0)
NOSWAP: ADD.L #1,A0
ADD.L #1,A1
ADD.L #1,D0
BRA LOOP
DONE: CMP.L #0,D1
BNE RESORT
MOVE.L (sp)+,A1
MOVE.L (sp)+,A0
MOVE.B (sp)+,D4
MOVE.B (sp)+,D3
MOVE.L (sp)+,D1
MOVE.L (sp)+,D0
MOVE.L (sp)+,D2 ; restore stack
RTS
* Variables and Strings
ORG $2000
INFILE DC.B 'infile.txt',0 ; input filename
OUTFILE DC.B 'outfile.txt',0 ; output filename
LENGTH DC.L 200
BUFFER DS.B LENGTH
END START ; last line of source
*~Font name~Courier New~
*~Font size~10~
*~Tab type~1~
*~Tab size~8~