flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
cod3b453 06 Jan 2012, 18:00
I think this should work:
Code: invoke ReadFile, [hFile], buffer, 1, no_bytes_read, 0 cmp [buffer], "T" jne exit sub esp,(5 * 4) invoke ReadFile; [hFile], buffer, 1, no_bytes_read, 0 cmp [buffer], "E" jne exit ; ... |
|||
![]() |
|
f0dder 06 Jan 2012, 18:29
rohagymeg: for this particular use, please do a full buffer read and then do an in-memory scan - it's going to be a lot less code, and ReadFile calls are pretty expensive.
cod3b453: very bad idea when interfacing with external code - you have no guarantee that even if it works now, it won't be broken for some previous or up-and-coming version of the external code. But for internal code which you have full control of, this is one of those optimizations that's sweet and "yeah, I'm an assembly coder" like ![]() As an exercise in how to save a few code bytes, a quick-and-naïve idea would be: Code: proc ReadAndTest test_value invoke ReadFile, [hFile], buffer, 1, no_bytes_read, 0 mov al, [test_value] cmp [buffer], al ret endp ;....... stuff.... invoke ReadAndTest, "T" jne exit invoke ReadAndTest, "E" jne exit invoke ReadAndTest, "S" jne exit invoke ReadAndTest, "T" jne exit ...not the approach I'd use, though, since as I mentioned above calls to ReadFile are expensive... and each invocation of ReadAndTest are 7 bytes at the call site. Furthermore, this approach requires global variables for hFile, buffer and no_bytes_read, where I generally prefer locals. _________________ ![]() |
|||
![]() |
|
rohagymeg 06 Jan 2012, 18:35
Thanks! I wanted to read into buffer line by line, but I don't know how to do it in a formal way. Is there a search function for finding the position of 0xD, 0xA (new line)
|
|||
![]() |
|
LocoDelAssembly 06 Jan 2012, 18:36
Although cod3b453 probably works, ReadFile is technically allowed to trash the parameters so perhaps you could just use a loop?
Code: pattern db "TEST" . . . mov ebx, -4 mov edi, pattern + 4 .read: invoke ReadFile, [hFile], buffer, 1, no_bytes_read, 0 mov al, [buffer] cmp al, [edi+ebx] jne exit inc ebx jnz .read |
|||
![]() |
|
MHajduk 06 Jan 2012, 18:40
f0dder wrote: ...not the approach I'd use, though, since as I mentioned above calls to ReadFile are expensive... and each invocation of ReadAndTest are 7 bytes at the call site. Furthermore, this approach requires global variables for hFile, buffer and no_bytes_read, where I generally prefer locals. I guess that rohagymeg wants to make something like a text parser, am I right? |
|||
![]() |
|
rohagymeg 06 Jan 2012, 18:43
I made a config.txt parser in c++. I'm remaking it in FASM. My big problem is how do I deal with ReadFile instead of GetLine.
|
|||
![]() |
|
Overflowz 06 Jan 2012, 18:45
Try something like this:
Code: proc someproc pushad some functions here popad ret endp This function will return nothing, thus will not destroy anything ![]() |
|||
![]() |
|
f0dder 06 Jan 2012, 18:47
rohagymeg wrote: Thanks! I wanted to read into buffer line by line, but I don't know how to do it in a formal way. Is there a search function for finding the position of 0xD, 0xA (new line) There's several ways to handle this, depending on your needs ![]() If you're dealing with 'sane' file sizes, you can either memory-map the file or read the entire file to memory - then you've got one big buffer you can do line-parsing in. If you need to deal with really huge input data, or you need your application to play nice if run under a Terminal Services machine, you'll want to process in chunks. I see you mention C++ - you're probably used to iostreams of fgetc. Both iostream and the FILE functions have their own internal buffering so they avoid calling ReadFile all the time. [url]This link[/url] has some stats that show why you don't want to call ReadFile repeatedly with small read sizes ![]() Building your own generic buffered file I/O isn't a trivial programming exercise, but not rocket science either - could be worth it for the learning experience. If you just need to parse smallish files without a lot of effort, I'd say read it into a buffer and parse it there. _________________ ![]() |
|||
![]() |
|
MHajduk 06 Jan 2012, 18:49
rohagymeg wrote: I made a config.txt parser in c++. I'm remaking it in FASM. My big problem is how do I deal with ReadFile instead of GetLine. |
|||
![]() |
|
rohagymeg 06 Jan 2012, 18:53
Thanks for the input people! This seems disgusting but that's how windows handles things
![]() |
|||
![]() |
|
f0dder 06 Jan 2012, 19:05
rohagymeg wrote: Thanks for the input people! This seems disgusting but that's how windows handles things _________________ ![]() |
|||
![]() |
|
cod3b453 06 Jan 2012, 20:38
f0dder wrote: ... ![]() |
|||
![]() |
|
f0dder 06 Jan 2012, 22:20
cod3b453 wrote:
![]() ![]() _________________ ![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.