Replay data structure, almost update to sort. This semester learned assembly language, several of which are the implementation of internal sorting algorithm. The following is a program designed to implement simple selection sequencing:
S0 SEGMENT STACK DW -DUP (?) TOP LABEL WORDS0 ENDSS1 segmenttip DB"Input ten number and separate the numbers with space:",0Dh0AH, -HARY DW -DUP (0) CRLF DB0Dh0AH, -HN DW0S1 ENDSS2 SEGMENT assume Ss:s0, Ds:s1, CS:S2, es:s1p PROC farMOVAX, S0MOVSS, AX LEA SP, TOPMOVAX, S1MOVDS, AXMOVAX, S1MOVES, AX LEA DX, TIPMOVAH,9Int +H LEA SI, ARY XOR DX, DXMOVELKTen MOVCX,TenINPUT: MOVAH,1Int +H CMP AL, -H; space-delimited charactersJE SAVEEnter a decimal number to deposit the number in the SI corresponding memory unit MOVDL, ALMOVAX, [SI]MULBLSUBClass -HADDAL, DLMOV[SI], AXJMPINPUTSAVE: ADDSI,2LOOP INPUTThe array is saved.LEA SI, ARYMOVDI, SIADDDI,2 ;D I in the position of the second element of the array MOVBp9 ; The number of SI moves and the number of times each comparison is 9 for the first timeGO: MOVCX, BP; number of cycles per comparison MOVBX, [SI]; the first numberCMPA:CMP BX, [DI]comparing the number of subsequent numbers to the current smallJbe CON; is more than the next MOVBX, [DI]; Replace the value in the register with the lowest value MOVAX, DI; AX holds the offset address of the minimum valueCON: ADDDI,2LOOP CMPA CMP AX,0 If AX is 0, then the value below is not smaller than the current valueJE NOat this time Si plus one, move to the second number next to the start of a cycle comparisonChange : MOVDX, [SI]; 78-83 rows Replace the current and minimum values PUSHDxMOV[SI], BXPOPDxMOVDI, AXMOV[DI], DXNO: ADDSI,2 MOVDI, SIADDDI,2 PagerPRINTDECBp, the number of cycles minus oneXOR Ax, Ax; Clear the contents of AX so that 76 rows can be judgedCMP BP,1JNE GOEXIT: MOVAH,4CH INT +HP Endpprint PROC nearPUSHSIPUSHCXPUSHAxPUSHDX LEA DX, CRLFMOVAH,9Int +H LEA SI, ARYMOVCX,TenL1: MOVAX, [SI]MOVN, AXPagerOUTPUTADDSI,2 MOVDx -HMOVAH,2Int +H LOOP L1POPDxPOPAxPOPCXPOPSIRETPRINT Endpoutput PROC nearPUSHAxPUSHBxPUSHCXPUSHDX XOR CX, CXMOVAX, NMOVBxTenL2:XOR DX, DX DIV BXPUSHDxINCCX CMP AX,0JNE L2L3: POPDxADDDx -HMOVAH,2Int +H LOOP L3POPDxPOPCXPOPBxPOPAxRETOUTPUT ENDPS2 ENDS END P
Assembly implementation sequencing--Simple selection sorting