史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   組合語言作業~插入排序~QQ (http://forum.slime.com.tw/thread164533.html)

kinco 2005-12-29 02:34 AM

組合語言作業~插入排序~QQ
 
小弟又來了~麻煩大大了~最後了 ~QQ
語法:

Assignment 2
Due :12/30/2005
(-20% for each day late)
(遲交的每天-20%)

•        The goal of assignment 2 is to learn to implement an assembly program using procedures.
and condition jmp
學習使用jmp實作一個組合程式。
•        In this assignment, you will implement an insertion sort program.  Your program should contain at least two procedures: insertion_sort for sorting a data array, and dump_array for displaying the sorted array.
你的程式只少需要包含2個功能:
1.        插入排序法(Insertion Sort):輸入數個數值,並以插入排序法由小至大將數值排序
2.        保存資料的陣列(dump_array):供你使用排序功能的陣列
•        In the assignment , u need let user input how many integers you want to sort and print the data
本程式中…你需要把使用者輸入的數字排序跟印出
•        arry before sort and after sort . The numbers of sorting integers is between 0 and 100.
本程式中…需要讓使用者輸入一個數字(介於0~100之間)
The following is a pseudo code of insertion sort:

=========================================
Insertion-Sort(A)

for j←2 for length[A]
  do key←A[j]
      △Insert A[j] into the sorted sequence A[1..j-1]
      i←j-1
      while i>0 and A[i]>key
        do A[i+1]←A[i]
            i←i-1
        A[i+1]←key
=========================================

•        Use WriteDec, WriteString, ReadDec, Crlf…etc. in Irvine32.inc to implement your program
* WriteDec:  在標準輸出中寫入一個32-bit無號整數,以十進位顯示
          mov    eax , 295
          call    WriteDec              ; 顯示 "295"
* WriteString:  寫入一個以null作結尾的字串到標準輸出
          prompt  BYTE  "Enter your name:" , 0
          mov        edx , OFFSET prompt
          call        WriteString
* Crlf : 換行
          call  Crlf
* ReadDec : ???
•        Graded will based on
o        60% A completely working program is finished.  The code should be complete or almost done (meaning the basic structure of the code is correct but the code may still have bugs), and it should have no compilation error.
o        (30%) The program produces correct results.
o        (10%) Readability.
•        Write Homework by yourself or discuss with classmates, but Never Copy , or Both
Graded will be zero.


mini 2005-12-29 06:58 PM

重點在將
for j←2 for length[A]
do key←A[j]
△Insert A[j] into the sorted sequence A[1..j-1]
i←j-1
while i>0 and A[i]>key
do A[i+1]←A[i]
i←i-1
A[i+1]←key

寫成組合語言即可

kinco 2005-12-30 10:01 AM

KEY是什麼?
引用:

作者: mini
重點在將
for j←2 for length
do key←A
△Insert A into the sorted sequence A
i←j-1
while i>0 and A>key
do A←A
i←i-1
A←key

寫成組合語言即可


mini 2005-12-30 12:12 PM

key 是一個暫存用變數
可以用 暫存器 或 記憶體變數 來實現
比如
for j←2 for length[A]
do key←A[j]

翻譯過來就變成
語法:

.data
key  Byte 1 DUP (0)
.code
      mov EBX,2        ;EBX 比作 j
      mov ECX,LENGTHOF A
NEXT:
      mov key,A+EBX ;A+EBX = A[j]
;...
      INC EBX
loop NEXT

因為個人沒學過 插入排序法
所以也不多說什麼

kinco 2005-12-30 03:30 PM

謝謝了~我在研究一下~


所有時間均為台北時間。現在的時間是 01:57 PM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1