home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / util / super_c / sortl.asm < prev    next >
Encoding:
Assembly Source File  |  1980-01-01  |  2.9 KB  |  121 lines

  1. ;       RAM Sort Function
  2.  
  3. _TEXT   SEGMENT  BYTE PUBLIC 'CODE'
  4. _TEXT   ENDS
  5. CONST   SEGMENT  WORD PUBLIC 'CONST'
  6. CONST   ENDS
  7. _BSS    SEGMENT  WORD PUBLIC 'BSS'
  8. _BSS    ENDS
  9. _DATA   SEGMENT  WORD PUBLIC 'DATA'
  10. _DATA   ENDS
  11.  
  12. DGROUP  GROUP   CONST,_BSS,_DATA
  13.  
  14.         ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  15.  
  16. PUBLIC  _sortLines
  17.  
  18. _DATA   SEGMENT
  19. EXTRN   __chkstk:NEAR
  20. EXTRN   _buffer:BYTE
  21. EXTRN   _lPtr:BYTE
  22. EXTRN   _nextLPtr:WORD
  23. EXTRN   _strcmp:NEAR
  24. _DATA   ENDS
  25.  
  26. _TEXT      SEGMENT
  27.  
  28. ; sortLines()
  29.  
  30.         PUBLIC  _sortLines
  31.  
  32. _sortLines PROC NEAR
  33.         push  bp
  34.         mov   bp,sp
  35.         mov   ax,10
  36.         call  __chkstk
  37.         push  si
  38.         push  di
  39.  
  40. ;       struct linePtr *sortLPtr;
  41. ;       struct linePtr *srchLPtr;
  42. ;       struct linePtr *lowLPtr;
  43. ;       struct linePtr newLPtr;
  44.  
  45.         newLPtr = 4
  46.         srchLPtr = 6
  47.         sortLPtr = 8
  48.         lowLPtr = 10
  49.  
  50. ;       for (sortLPtr = lPtr; sortLPtr < nextLPtr; sortLPtr++) {
  51.         mov     WORD PTR [bp-sortLPtr],OFFSET DGROUP:_lPtr
  52.         jmp     SHORT $L20002
  53. $F46:
  54.  
  55. ;               for (lowLPtr = srchLPtr = sortLPtr;
  56. ;                    srchLPtr < nextLPtr; srchLPtr++)
  57.         mov     si,[bp-sortLPtr]
  58.         mov     di,si
  59.         jmp     SHORT $L20001
  60. $F50:
  61.  
  62. ; *** New code ***
  63. ;                       if (strcmp(lowLPtr->sortAt,srchLPtr->sortAt) > 0)
  64.         push    di                      ; Save si/di
  65.         push    si
  66.         mov     di,WORD PTR [di+2]      ; di = lowLPtr->sortAt
  67.         mov     si,WORD PTR [si+2]      ; si = srchLPtr->sortAt
  68.  
  69. loop:   lods    BYTE PTR [si]           ; Get the next byte to compare
  70.         scas    BYTE PTR [di]           ; Compare it
  71.         jne     noteq                   ; If they don't match
  72.         or      al,al                   ; End-of-string?
  73.         jnz     loop                    ; If not
  74.         pop     si                      ; Pop si/di
  75.         pop     di
  76.         jmp     $FC51                   ; The strings are equal
  77. noteq:  pop     si                      ; Pop si/di
  78.         pop     di
  79.         ja      $FC51                   ; Jump if string 1 is more than 2
  80. ; ***
  81.  
  82. ;                               lowLPtr = srchLPtr;
  83.         mov     di,si
  84.  
  85. ;               newLPtr = *sortLPtr;
  86. $FC51:
  87.         add     si,4
  88. $L20001:
  89.         cmp     _nextLPtr,si
  90.         ja      $F50
  91.         mov     bx,[bp-sortLPtr]
  92.         mov     ax,[bx]
  93.         mov     dx,[di]
  94.         mov     [bx],dx
  95.         mov     [di],ax
  96.         mov     ax,[bx+2]
  97.         mov     dx,[di+2]
  98.         mov     [bx+2],dx
  99.         mov     [di+2],ax
  100.  
  101. ;       };
  102.         add     WORD PTR [bp-sortLPtr],4
  103. $L20002:
  104.         mov     ax,_nextLPtr
  105.         cmp     [bp-sortLPtr],ax
  106.         jb      $F46
  107.  
  108. ; }
  109.         pop     di
  110.         pop     si
  111.         mov     sp,bp
  112.         pop     bp
  113.         ret
  114.  
  115. _sortLines ENDP
  116.  
  117. _TEXT   ENDS
  118.  
  119.         END
  120.  
  121.