Guest User

Untitled

a guest
Apr 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.39 KB | None | 0 0
  1. procedure       _Copy{ s : ShortString; index, count : Integer ) : ShortString};
  2. asm
  3. {     ->EAX     Source string                   }
  4. {       EDX     index                           }
  5. {       ECX     count                           }
  6. {       [ESP+4] Pointer to result string        }
  7.  
  8.         PUSH    ESI
  9.         PUSH    EDI
  10.  
  11.         MOV     ESI,EAX
  12.         MOV     EDI,[ESP+8+4]
  13.  
  14.         XOR     EAX,EAX
  15.         OR      AL,[ESI]
  16.         JZ      @@srcEmpty
  17.  
  18. {       limit index to satisfy 1 <= index <= Length(src) }
  19.  
  20.         TEST    EDX,EDX
  21.         JLE     @@smallInx
  22.         CMP     EDX,EAX
  23.         JG      @@bigInx
  24. @@cont1:
  25.  
  26. {       limit count to satisfy 0 <= count <= Length(src) - index + 1    }
  27.  
  28.         SUB     EAX,EDX { calculate Length(src) - index + 1     }
  29.         INC     EAX
  30.         TEST    ECX,ECX
  31.         JL      @@smallCount
  32.         CMP     ECX,EAX
  33.         JG      @@bigCount
  34. @@cont2:
  35.  
  36.         ADD     ESI,EDX
  37.  
  38.         MOV     [EDI],CL
  39.         INC     EDI
  40.         REP     MOVSB
  41.         JMP     @@exit
  42.  
  43. @@smallInx:
  44.         MOV     EDX,1
  45.         JMP     @@cont1
  46. @@bigInx:
  47. {       MOV     EDX,EAX
  48.         JMP     @@cont1 }
  49. @@smallCount:
  50.         XOR     ECX,ECX
  51.         JMP     @@cont2
  52. @@bigCount:
  53.         MOV     ECX,EAX
  54.         JMP     @@cont2
  55. @@srcEmpty:
  56.         MOV     [EDI],AL
  57. @@exit:
  58.         POP     EDI
  59.         POP     ESI
  60.     RET 4
  61. end;
Add Comment
Please, Sign In to add comment