Salut
Comment écrire un programme en Assembleur du microprocesseur 80286, qui permet de classer les données d'une zone mémoire selon l'ordre croissant (du plus petit au plus grand).
ex 4 7 6 4 9 1 0
Et merci
Salut
Comment écrire un programme en Assembleur du microprocesseur 80286, qui permet de classer les données d'une zone mémoire selon l'ordre croissant (du plus petit au plus grand).
ex 4 7 6 4 9 1 0
Et merci
ce n'est pas une question d'assembleur, mais d'algorythme..
puis, ici, je ne sais pas pourquoi, mais on dirait bien un site de travaux dirigés...
premierement, il faut reviser les cours, essayer de comprendre ce qu'est un programme au lieu de demander la solution a un exercice aussi simple...
ou alors, tu me donnes ton diplome des que tu l'obtiens.( et ouais , je suis issu de la classe des gueux, celle qui n'a meme pas les moyen de continuer les etudes et doit charbonner pour survivre. snif, ouin, rheu, rheu)
pour classer dans un ordre, rien de tel que de bonnes comparaisons iteratives, la premiere etant sensée trouver le premier terme du classement, les autres vont de soit.
papier, crayon, organigramme, creusage de meninges
Oui, le tri a bulles est la methode la plus simple (pas la plus rapide mais
quand c'est code en assembleur sur des machines a plusieurs GHz c'est quand-meme rapide )
Tu peux aller voir ici : http://fr.wikipedia.org/wiki/Tri_%C3%A0_bulles
a+ Francois
Tri à bulle
Bon appétit
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185 .MODEL SMALL .STACK 100H .DATA PROMPT_1 DB 'The contents of the array before sorting : $' PROMPT_2 DB 0DH,0AH,'The contents of the array after sorting : $' ARRAY DB 5,3,9,0,2,6,1,7,8,4 .CODE MAIN PROC MOV AX, @DATA ; initialize DS MOV DS, AX MOV BX, 10 ; set BX=10 LEA DX, PROMPT_1 ; load and display the string PROMPT_1 MOV AH, 9 INT 21H LEA SI, ARRAY ; set SI=offset address of ARRAY CALL PRINT_ARRAY ; call the procedure PRINT_ARRAY LEA SI, ARRAY ; set SI=offset address of the ARRAY CALL BUBBLE_SORT ; call the procedure BUBBLE_SORT LEA DX, PROMPT_2 ; load and display the string PROMPT_2 MOV AH, 9 INT 21H LEA SI, ARRAY ; set SI=offset address of ARRAY CALL PRINT_ARRAY ; call the procedure PRINT_ARRAY MOV AH, 4CH ; return control to DOS INT 21H MAIN ENDP ;**************************************************************************; ;**************************************************************************; ;------------------------- Procedure Definitions ------------------------; ;**************************************************************************; ;**************************************************************************; ;**************************************************************************; ;----------------------------- PRINT_ARRAY ------------------------------; ;**************************************************************************; PRINT_ARRAY PROC ; this procedure will print the elements of a given array ; input : SI=offset address of the array ; : BX=size of the array ; output : none PUSH AX ; push AX onto the STACK PUSH CX ; push CX onto the STACK PUSH DX ; push DX onto the STACK MOV CX, BX ; set CX=BX @PRINT_ARRAY: ; loop label XOR AH, AH ; clear AH MOV AL, [SI] ; set AL=[SI] CALL OUTDEC ; call the procedure OUTDEC MOV AH, 2 ; set output function MOV DL, 20H ; set DL=20H INT 21H ; print a character INC SI ; set SI=SI+1 LOOP @PRINT_ARRAY ; jump to label @PRINT_ARRAY while CX!=0 POP DX ; pop a value from STACK into DX POP CX ; pop a value from STACK into CX POP AX ; pop a value from STACK into AX RET ; return control to the calling procedure PRINT_ARRAY ENDP ;**************************************************************************; ;---------------------------- BUBBLE_SORT -------------------------------; ;**************************************************************************; BUBBLE_SORT PROC ; this procedure will sort the array in ascending order ; input : SI=offset address of the array ; : BX=array size ; output : none PUSH AX ; push AX onto the STACK PUSH BX ; push BX onto the STACK PUSH CX ; push CX onto the STACK PUSH DX ; push DX onto the STACK PUSH DI ; push DI onto the STACK MOV AX, SI ; set AX=SI MOV CX, BX ; set CX=BX DEC CX ; set CX=CX-1 @OUTER_LOOP: ; loop label MOV BX, CX ; set BX=CX MOV SI, AX ; set SI=AX MOV DI, AX ; set DI=AX INC DI ; set DI=DI+1 @INNER_LOOP: ; loop label MOV DL, [SI] ; set DL=[SI] CMP DL, [DI] ; compare DL with [DI] JNG @SKIP_EXCHANGE ; jump to label @SKIP_EXCHANGE if DL<[DI] XCHG DL, [DI] ; set DL=[DI], [DI]=DL MOV [SI], DL ; set [SI]=DL @SKIP_EXCHANGE: ; jump label INC SI ; set SI=SI+1 INC DI ; set DI=DI+1 DEC BX ; set BX=BX-1 JNZ @INNER_LOOP ; jump to label @INNER_LOOP if BX!=0 LOOP @OUTER_LOOP ; jump to label @OUTER_LOOP while CX!=0 POP DI ; pop a value from STACK into DI POP DX ; pop a value from STACK into DX POP CX ; pop a value from STACK into CX POP BX ; pop a value from STACK into BX POP AX ; pop a value from STACK into AX RET ; return control to the calling procedure BUBBLE_SORT ENDP ;**************************************************************************; ;-------------------------------- OUTDEC --------------------------------; ;**************************************************************************; OUTDEC PROC ; this procedure will display a decimal number ; input : AX ; output : none PUSH BX ; push BX onto the STACK PUSH CX ; push CX onto the STACK PUSH DX ; push DX onto the STACK XOR CX, CX ; clear CX MOV BX, 10 ; set BX=10 @OUTPUT: ; loop label XOR DX, DX ; clear DX DIV BX ; divide AX by BX PUSH DX ; push DX onto the STACK INC CX ; increment CX OR AX, AX ; take OR of Ax with AX JNE @OUTPUT ; jump to label @OUTPUT if ZF=0 MOV AH, 2 ; set output function @DISPLAY: ; loop label POP DX ; pop a value from STACK to DX OR DL, 30H ; convert decimal to ascii code INT 21H ; print a character LOOP @DISPLAY ; jump to label @DISPLAY if CX!=0 POP DX ; pop a value from STACK into DX POP CX ; pop a value from STACK into CX POP BX ; pop a value from STACK into BX RET ; return control to the calling procedure OUTDEC ENDP ;**************************************************************************; ;--------------------------------------------------------------------------; ;**************************************************************************; END MAIN ;**************************************************************************; ;**************************************************************************; ;------------------------------ THE END ---------------------------------; ;**************************************************************************; ;**************************************************************************;
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager