Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure _Copy{ s : ShortString; index, count : Integer ) : ShortString};
- asm
- { ->EAX Source string }
- { EDX index }
- { ECX count }
- { [ESP+4] Pointer to result string }
- PUSH ESI
- PUSH EDI
- MOV ESI,EAX
- MOV EDI,[ESP+8+4]
- XOR EAX,EAX
- OR AL,[ESI]
- JZ @@srcEmpty
- { limit index to satisfy 1 <= index <= Length(src) }
- TEST EDX,EDX
- JLE @@smallInx
- CMP EDX,EAX
- JG @@bigInx
- @@cont1:
- { limit count to satisfy 0 <= count <= Length(src) - index + 1 }
- SUB EAX,EDX { calculate Length(src) - index + 1 }
- INC EAX
- TEST ECX,ECX
- JL @@smallCount
- CMP ECX,EAX
- JG @@bigCount
- @@cont2:
- ADD ESI,EDX
- MOV [EDI],CL
- INC EDI
- REP MOVSB
- JMP @@exit
- @@smallInx:
- MOV EDX,1
- JMP @@cont1
- @@bigInx:
- { MOV EDX,EAX
- JMP @@cont1 }
- @@smallCount:
- XOR ECX,ECX
- JMP @@cont2
- @@bigCount:
- MOV ECX,EAX
- JMP @@cont2
- @@srcEmpty:
- MOV [EDI],AL
- @@exit:
- POP EDI
- POP ESI
- RET 4
- end;
Add Comment
Please, Sign In to add comment