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

📄 bubblesort.asm

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

.code

IFNDEF PURE_ALGORITHM


  BubbleSort PROTO :DWORD, :DWORD

  
BubbleSort PROC Arr:DWORD, count:DWORD

    mov    esi, Arr

    mov    ebx, esi
    lea    edi, [ebx - 4]
    mov    ecx, count
    lea    ebx, [ebx + ecx*4]

  @Loop1:
    sub    ebx, 4
    cmp    ebx, esi
    jna    @Return

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

      mov    eax, edi

    @Loop2:
      add    eax, 4
      cmp    eax, ebx
      jnb    @Loop1

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

  push   ebx
    lea    ebx, [eax + 4]
    DelayAfterComparison eax, ebx
  pop    ebx
;-------------------------------------------------------------------------------

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

        mov    ecx, DWORD PTR [eax]
        mov    DWORD PTR [eax], edx
        mov    DWORD PTR [eax + 4], ecx

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

  RefreshElement eax
  push   eax
    add    eax, 4
    RefreshElement eax
  pop    eax

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

        jmp    @Loop2



@Return:
  ret

BubbleSort ENDP


ELSE

  BubbleSort_PURE PROTO :DWORD, :DWORD


BubbleSort_PURE PROC Arr:DWORD, count:DWORD

    mov    esi, Arr

    mov    ebx, esi
    lea    edi, [ebx - 4]
    mov    ecx, count
    lea    ebx, [ebx + ecx*4]

  @Loop1:
    sub    ebx, 4
    cmp    ebx, esi
    jna    @Return

      mov    eax, edi

    @Loop2:
      add    eax, 4
      cmp    eax, ebx
      jnb    @Loop1

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

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

        mov    ecx, DWORD PTR [eax]
        mov    DWORD PTR [eax], edx
        mov    DWORD PTR [eax + 4], ecx

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

        jmp    @Loop2



@Return:
  ret

BubbleSort_PURE ENDP


ENDIF

⌨️ 快捷键说明

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