flat assembler
Message board for the users of flat assembler.
Index
> Windows > Help removing new line from strings. |
Author |
|
kohlrak 01 Jan 2007, 19:10
XD
i'll give you my own untested code to see if you can figure it out from that, since i'm not exactly sure what everything in your program does (due to lack of experience). Code: macro erase10 __erase10string { mov ecx, 0 mov ebx, __erase10string ;So far it should be obvious... loopy: mov al, [ecx+ebx] and al, 10 ;check if 10 jnz endofloop ;exit loop inc ecx ;increment to try again jmp loopy ;Go back to start of loop endofloop: ;exit of loop mov [ecx+ebx], byte 0 ;Terminates, ecx should not have been incremented by one so it should still be on 10. } Quote: scas subtracts the destination string element from AL, AX, or EAX (depending on the size of string element) and updates the flags AF, SF, ZF, PF, CF and OF. If the values are equal, ZF is set, otherwise it is cleared. The operand should be the destination string element addressed by DI or EDI. I think that means that scas (scasb in your case) goes BACKWORDS, but i'm not sure. You should always know the max size of a variable, so if it does go backwords, you can always to the scas from the max size. But i could be wrong on that. That and the fact that you're storing EDI into eax to back it up (i'd use push edi) and print edi out. Incase it dosn't go backwords, try directly placing string's address into edi and printinting the string from EDI using pop edi if you use push edi to back it up, because it appaers that your code is using eax when you're trying to use eax for something else. |
|||
01 Jan 2007, 19:10 |
|
Goplat 01 Jan 2007, 19:41
superj_2004: SCASx compares with AL, not DL. Also, you have to set ECX to the maximum length to search for first.
kohlrak: SCASx can go backwards if the direction flag is set, but that's no different from all the other string instructions. Quote:
That should be CMP/JZ, not AND/JNZ. |
|||
01 Jan 2007, 19:41 |
|
kohlrak 01 Jan 2007, 19:44
Oops.
EDIT: now that i read the deffiniton again with new understanding, it appears to imply that it only checks one value then exits it's little scan, rather than searching the whole string. |
|||
01 Jan 2007, 19:44 |
|
superj_2004 02 Jan 2007, 02:07
Thanks a lot!
|
|||
02 Jan 2007, 02:07 |
|
hutch-- 02 Jan 2007, 14:04
I enjoy playing with FASM from time to time. here is a simple algo put into a library module that will remove any conbination of ascii 13 and 10.
Code: ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ format MS COFF section '.text' code readable executable public _remlf as "remlf@4" ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ _remlf: ; -- ----------------------------------------------------------- ; replaces any combination of ascii 13 & 10 with a single space. ; ------------------------------------------------------------- mov ecx, [esp+4] mov edx, [esp+4] sub ecx, 1 @@: add ecx, 1 backin: movzx eax, BYTE [ecx] test eax, eax ; test for terminator jz zero cmp eax, 13 ; test for CR je crlfeed cmp eax, 10 ; test for LF je crlfeed mov [edx], al ; write byte to destination add edx, 1 jmp @B crlfeed: add ecx, 1 movzx eax, BYTE [ecx] cmp eax, 13 ; test for CR je crlfeed cmp eax, 10 ; test for LF je crlfeed test eax, eax ; test for terminator jz zero mov BYTE [edx], 32 ; write a space to replace add edx, 1 ; the CRLF combination jmp backin zero: mov BYTE [edx], 0 mov eax, [esp+4] ret 4 ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ Regards, hutch at movsd dot com |
|||
02 Jan 2007, 14:04 |
|
hamoz 09 Feb 2007, 02:58
Hello hutch--,
can you tell me how can I execute your MSCOFF example coz I have no idea. thanks alot |
|||
09 Feb 2007, 02:58 |
|
hutch-- 09 Feb 2007, 19:19
hamoz,
The procedure only takes one argument, IE "[esp+4]" and it writes the results back over the same source. Code: push [address_of_string] call remlf Result is written to the original string. Regards, hutch at movsd dot com |
|||
09 Feb 2007, 19:19 |
|
okasvi 10 Feb 2007, 10:04
hamoz wrote: Hello hutch--, It would require linking, I guess hutch-- is used to that Anyway, you can easily make it to work in your own srcs which doesnt require linking, just copy&paste everything inbetween last two lines of ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ and place it into your code where you keep procs, and ofc add ;remlf by hutch-- somewhere in your sources Two things I would do if I would use it in my one-file-source is to prefix with dot(.) all labels after _remlf, and change ret to retn as it's not using proc macro anyway. _________________ When We Ride On Our Enemies support reverse smileys |: |
|||
10 Feb 2007, 10:04 |
|
hamoz 10 Feb 2007, 18:35
Thanks guys.....but Can anyone do it here for me, the last chance
|
|||
10 Feb 2007, 18:35 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.