flat assembler
Message board for the users of flat assembler.
Index
> Windows > Mid String |
Author |
|
revolution 26 Aug 2009, 04:35
You are not specifying a destination. The value in edx has not been initialised.
|
|||
26 Aug 2009, 04:35 |
|
Pirata Derek 26 Aug 2009, 08:06
I don't know how you want to do, but try this:
Code: ; Copy a piece of a string to another place ; INPUT Parameters: ; PUSHD source string (offset) ; PUSHD the bytes to skip from start (bytes) ; PUSHD the bytes to copy (bytes) ; PUSHD destination string (offset) proc MidString source,start,count,destination mov ecx,[count] jecxz .exit ; if zero then exit mov esi,[source] add esi,[start] mov edi,[destination] cld rep movsb xor al,al ; to terminate the second string stosb .exit: ret endp This procedure is more simple, smaller and faster Last edited by Pirata Derek on 27 Aug 2009, 14:45; edited 1 time in total |
|||
26 Aug 2009, 08:06 |
|
vid 26 Aug 2009, 10:52
from FASMLIB:
str.sub Code: ;; @name str.sub ;; @desc ;; Extracts substring from another string. ;; @arg dest ;; Pointer to destination string buffer. ;; @arg destlen ;; Size of destination string buffer. ;; @arg src ;; Pointer to source string. ;; @arg srclen ;; Size of source string buffer. ;; You can set this to -1 (FFFFFFFFh) if string is quaranteed to be properly zero-terminated. ;; @arg index ;; Position in source string from where we start extracting. ;; Position 0 corresponds to first character, included. ;; @arg len ;; Length of string we want to extract. ;; @ret ;; CF set on error, otherwise ;; EAX = dest, and ;; OF set if string overlapped and less than len characters were copied ;; @err ERR_OUT_OF_RANGE ;; Position is outside of destination string, pos >= strlen(dest). ;; You are trying to extract string from behind end of source string. ;; @err ERR_BUFFER_OVERFLOW ;; Destination buffer is not big enough. ;; Only first destlen bytes of extracted string were written. ;; String in destination buffer is NOT zero terminated. ;; @err ERR_ZERO_SIZE ;; destlen=0 or srclen=0. ;; @note If source string doesn't contain enough characters from given index, ;; string shorter than len is copied and procedure returns with OF set. ;; @note If len=0, destination buffer is filled with empty string. proc str.sub dest, destlen, src, srclen, index, len push ecx esi pushf btc dword [esp], 11 ;clear OF cld ;error if destlen=0 cmp [destlen], 0 je .error_destlen_zero ;error if srclen=0 cmp [srclen], 0 je .error_srclen_zero ;if len is zero, we just fill dest with empty string cmp [len], 0 je .len_is_zero ;ECX = length of source string libcall str.len, [src], [srclen] jc .rc mov ecx, eax ;ERR_OUT_OF_RANGE if index >= length of source string cmp [index], ecx jae .error_index_out_of_range ;ECX = required length for the new string = min(index+len, str.len(string)) - index mov eax, [index] add eax, [len] cmp eax, ecx jbe @f mov eax, ecx bts dword [esp], 11 ;set OF @@: sub eax, [index] mov ecx, eax ;ECX = length in dest buffer = min(ECX, destlen) mov eax, [destlen] cmp ecx, eax cmova ecx, eax ;get position in source string from where to copy mov esi, [src] add esi, [index] ;copy actual part of string that should be copied libcall mem.copy, [dest], esi, ecx jc .rc ;error if there is no place for ending zero, eg. if ECX = destlen cmp ecx, [destlen] je .error_dest_buffer_full ;otherwise add ending zero add ecx, [dest] mov byte [ecx], 0 ;return dest .done: mov eax, [dest] .rnc: btc dword [esp], 1 ;clear CF .r: popf pop esi ecx ret .rc: bts dword [esp], 1 ;set CF jmp .r ;length of desired string is zero, just fill dest with empty string .len_is_zero: mov eax, [dest] mov byte [eax], 0 jmp .done .error_dest_buffer_full: mov eax, ERR_BUFFER_FULL jmp .rc .error_destlen_zero: mov eax, ERR_ZERO_SIZE jmp .rc .error_srclen_zero: mov eax, ERR_ZERO_SIZE jmp .rc .error_index_out_of_range: mov eax, ERR_OUT_OF_RANGE jmp .rc endp |
|||
26 Aug 2009, 10:52 |
|
spacebuddy 26 Aug 2009, 17:03
Thanks all, got it working
one more question, how do I use the fasmlib in my program? |
|||
26 Aug 2009, 17:03 |
|
windwakr 26 Aug 2009, 17:06
Have you seen the website for it?
http://fasmlib.x86asm.net/ fasmlib website wrote:
I'm sure there should be enough there to help you learn how to use it. |
|||
26 Aug 2009, 17:06 |
|
r22 26 Aug 2009, 17:17
Should be a MAIN thread not WINDOWS.
If your trying to emulate the VB Mid than the extra destination parameter kind of throws it off. You could allocate memory for the new string in your procedure and return the address. Or you could just return the pointer in your src string to the new mid'd location. Code: ;;Equivalent to MyString = Mid(MyString, Start, Count) proc Mid source,start,count MOV eax,[source] ADD eax,[start] MOV ecx,[count] MOV byte[eax+ecx],0 endp |
|||
26 Aug 2009, 17:17 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.