VC6彙編第三次上機實驗
阿新 • • 發佈:2018-11-01
實驗目標
1)從鍵盤接收多個有符號整數
2)對輸入的多個整數進行排序
3)再次接收使用者輸入的一個整數,並在排序結果中查詢;
4)以二進位制編碼輸出下標。若未找到,則輸出提示。
實驗程式碼
TITLE Integer Summation Program (Sum2.asm) INCLUDE Irvine32.inc INTEGER_COUNT = 5 .data str1 BYTE "Enter a signed integer: ",0 str2 BYTE "The sum of the integers is ",0 str3 BYTE "The BubbleSort result is:",0 str4 BYTE "Please input the finding number:",0 str5 BYTE "找到了,二進位制下標為:",0 str6 BYTE "沒有找到該數字!!",0 array DWORD INTEGER_COUNT DUP(?) ARRAY_SIZE = 20 Array1 DWORD ARRAY_SIZE DUP(?) .code main PROC call Clrscr mov esi,OFFSET array mov ecx,INTEGER_COUNT call PromptForIntegers call BubbleSort call DisplayResult call InputFindNum call FindNum exit main ENDP ;冒泡降序 BubbleSort proc uses eax ecx esi ; esi指向要排序的雙字陣列,ecx為元素個數 Dec ecx L1:push ecx push esi L2:mov eax , [esi] cmp eax , [esi + 4] jg L3 xchg eax , [esi+4] mov [esi] ,eax L3:add esi ,4 loop L2 pop esi pop ecx Loop L1 ret BubbleSort endp ;輸入數字 PromptForIntegers PROC USES ecx edx esi mov edx,OFFSET str1 L1: call WriteString call ReadInt call Crlf mov [esi],eax add esi,TYPE DWORD loop L1 ret PromptForIntegers ENDP ;輸入要查詢的數字 InputFindNum PROC USES edx mov edx,OFFSET str4 call WriteString call ReadInt call Crlf ;輸入之後,新的數字儲存在EAX裡面 ;call DumpRegs ret InputFindNum ENDP ;查詢數字 FindNum PROC USES esi ecx edx ebx L1:cmp eax,[esi] je Feng1 add esi,TYPE DWORD loop L1 mov edx,OFFSET str6 call WriteString ret Feng1:mov edx,OFFSET str5 mov ebx,INTEGER_COUNT sub ebx,ecx mov eax,ebx call WriteString call WriteBin call Crlf ret FindNum ENDP ;列印排序結果 DisplayResult PROC USES edx ecx esi mov edx,OFFSET str3 call WriteString call Crlf mov eax,0 L1:mov eax,[esi] add esi,TYPE DWORD call WriteInt call Crlf Loop L1 ret DisplayResult ENDP END main