⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 selectionsort.asm

📁 一个演示了用汇编语言编写的数据排序算法,源代码非常详细
💻 ASM
字号:
; Date: 11.03.2004
; last modification: 27.03.2004

.code

IFNDEF PURE_ALGORITHM


  SelectionSort PROTO :DWORD, :DWORD


SelectionSort PROC Arr:DWORD, count:DWORD

    mov    ebx, Arr
    sub    ebx, 4
    mov    esi, count
    shl    esi, 2
    add    esi, ebx

  @Loop1:
    add    ebx, 4
    cmp    ebx, esi
    jnb    @Return

;-------------------------------------------------------------------------------
  DelayAfterPass
;-------------------------------------------------------------------------------

      mov    edi, ebx
      mov    eax, ebx

    @Loop2:
      add    eax, 4
      cmp    eax, esi
      ja     @Loop2a

;-------------------------------------------------------------------------------
  IncCMPCounter

  DelayAfterComparison eax, edi
;-------------------------------------------------------------------------------

        mov    edx, DWORD PTR [eax]
        cmp    DWORD PTR [edi], edx
        jna    @Loop2

        mov    edi, eax
        jmp    @Loop2

    @Loop2a:

      cmp    edi, ebx
      je     @Loop1

      mov    edx, DWORD PTR [edi]
      mov    ecx, DWORD PTR [ebx]
      mov    DWORD PTR [edi], ecx
      mov    DWORD PTR [ebx], edx

;-------------------------------------------------------------------------------
  IncMOVCounter

  RefreshElement edi
  RefreshElement ebx

  DelayAfterExchange
;-------------------------------------------------------------------------------

      jmp    @Loop1



@Return:
  ret

SelectionSort ENDP


ELSE


  SelectionSort_PURE PROTO :DWORD, :DWORD


SelectionSort_PURE PROC Arr:DWORD, count:DWORD

    mov    ebx, Arr
    sub    ebx, 4
    mov    esi, count
    shl    esi, 2
    add    esi, ebx

  @Loop1:
    add    ebx, 4
    cmp    ebx, esi
    jnb    @Return

      mov    edi, ebx
      mov    eax, ebx

    @Loop2:
      add    eax, 4
      cmp    eax, esi
      ja     @Loop2a

;-------------------------------------------------------------------------------
  IncCMPCounter
;-------------------------------------------------------------------------------

        mov    edx, DWORD PTR [eax]
        cmp    DWORD PTR [edi], edx
        jna    @Loop2

        mov    edi, eax
        jmp    @Loop2

    @Loop2a:

      cmp    edi, ebx
      je     @Loop1

      mov    edx, DWORD PTR [edi]
      mov    ecx, DWORD PTR [ebx]
      mov    DWORD PTR [edi], ecx
      mov    DWORD PTR [ebx], edx

;-------------------------------------------------------------------------------
  IncMOVCounter
;-------------------------------------------------------------------------------

      jmp    @Loop1



@Return:
  ret

SelectionSort_PURE ENDP


ENDIF

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -