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

📄 prog40b.asm

📁 主要是8051源代码
💻 ASM
字号:
;  PROG40b - Bubble Sort
;
;  This Application Loads the Top 128 Scratchpad Registers with a Psuedo Random
;   Value and Then Sorts them Using a Single Pass Bubble Sort Algorithm.
;
;  Myke Predko
;  98.04.08
;
;  Hardware Notes:
;  DS80C320 is used as the Microcontroller
;   - This Program Only Runs in the UMPS Simulator

;  Constant Declarations
ArrayStart EQU 010h             ;  Start of the Array to Sort
ArrayEnd   EQU 0FFh
Random     EQU 0B5h             ;  181 is the Psuedo-Random Value

;  Variable Declarations
 define EndLoc=R2               ;  End Location for the Sort
 define ArrayIndex=R0           ;  Use R0 as An Offset into the Array for Sorting
 define CurHigh=R1              ;  The Current High Value for the Sorting


;  Macros


;  Mainline
 org 0                          ;  Execution Starts Here

  acall   Randomize             ;  Randomize the Memory

  acall   Sort                  ;  Sort the Values

Loop:                           ;  When Complete, Loop Forever
  ajmp    Loop


Randomize:                      ;  Randomize the Values using the Prime Addition

  mov     R0,#ArrayStart        ;  Use R0 as Index to the Address to be Written To
  mov     A,#Random             ;  "A" Contains the Random Seed

RandomLoop:                     ;  Loop Here Until the Memory Has been Randomized

  mov     @R0,A                 ;  Save the Current Value in "A"

  add     A,#Random             ;  Add the Random Value In

  inc     R0                    ;  Point to the Next Address and Loop Until Full
  cjne    R0,#LOW(ArrayEnd+1),RandomLoop

  ret


Sort:                           ;  Sort the Value

  mov     EndLoc,#LOW(ArrayEnd+1)

SortLoop1:                      ;  Setup the Array Information

  mov     ArrayIndex,#LOW(ArrayStart+1)  ;  Current Pointer is in R0
  mov     R1,#ArrayStart

SortLoop2:                      ;  Loop Here Until ArrayIndex == EndLoc

  mov     A,@R0                 ;  Load the Next Value to Check
  clr     C
  subb    A,@R1                 ;  Do we Have a Higher Value

  jnc     SortLoopSkip          ;  Yes, Leave as Is

  mov     A,@R1                 ;  Swap the Values
  xch     A,@R0
  mov     @R1,A

SortLoopSkip:

  inc     R0                    ;  Point to the Next Test Value
  inc     R1                    ;  Point to the Next Previous Value 

  mov     A,R0                  ;  Are we At the End?
  xrl     A,EndLoc

  jnz     SortLoop2             ;  Nope...  

  dec     EndLoc

  mov     A,EndLoc              ;  Are we at the Start of the Array?
  clr     C
  subb    A,#ArrayStart+1       ;  Stop at One After the First

  jnz     SortLoop1

  ret                           ;  Everything Should be Sorted

⌨️ 快捷键说明

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