flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
madmatt
a simpler way would be to use 'fscanf':
local x:DWORD, y:DWORD, z:DWORD cinvoke fscanf, "%f %f %f", addr x, addr y, addr z do this for each set of 3 floats. |
|||
![]() |
|
vid
Using format string " %f , %f , %f" should also skip commas from input. Value other than 3 returned by fscanf() means there was some input error. Note that this way treats all whitespace the same - all spaces, tabs, and end-of-line characters are skipped by space in format string.
|
|||
![]() |
|
ctl3d32
Thanks guys, but let's consider that 'Data.txt' contains an unknown ammount of elements, i.e., 'Data.txt' could be any of, for example, this:
Code: 1.34, 3.45, 6.78, 2.00,-45.1, 1.00, 4.65 or this: Code: 1.34, 3.45, 6.78, 2.00 3.34, 7.45, 4.78, 1.00 1.94, 3.49, 9.79, 7.00 "%f, %f, %f" means to me that my input data structure has to be fixed and known before using fscanf. What i mean is: if i want to read the first example, should i use "%f, %f, %f, %f, %f, %f, %f"? If yes, that is not what i want. Because i don't know how many elements my arrays will have. Thanks, ctl3d32 |
|||
![]() |
|
madmatt
If you don't know the count or the count keeps changing you can read in one float at a time.
Code: local floatdata:DWORD, count:DWORD mov [count],0 .repeat cinvoke fscanf, "%f", addr floatdata inc [count] mov edx, [count] fld [floatdata] fstp [floatarraydata + edx*4] .until eax = 0 | eax = EOF ;don't know what the value is for EOF. Not sure how fast this would go on large data sets. |
|||
![]() |
|
JohnFound
Recently I tend to use binary file formats, as more asm-adequate. This simple transition can save you tons of code lines and to speed up the program (depending on the size of the files processed).
At the same time, using binary files makes them hard to be manually edited. So, I though about some common binary data format, that to be easy for human reading and editing (with any hex editor, or with very simple specialized editor) and in the same time to allow natural machine processing. I don't have solution for such format (or even suggestion) but wrote this just as a ground for meditation. ![]() |
|||
![]() |
|
vid
madmatt: You forgot to include space in your input format string. Should be " %f", in order to skip blanks between numbers (or is this done by default? I don't think so).
JohnFound: Depends on what you are willing to use. Compared to no library at all, I agree with you. Compared to using libc, I think direct binary format is less optimal solution. |
|||
![]() |
|
JohnFound
vid: Using text files to store data have only two real advantages 1. The format is human readable and editable, so the programmer can leave the editing to the user, not bothering with the complex data editors.
2. The format can be complex and thus flexible and expandable. On the other hand, the programs deal with binary formats very fast and easy, what is not true for text formats. Using reusable code (libc for example) only makes creating the program easy, not the execution. As a price for the programmer laziness the program have to make unnecessary complex processing only to read (write) several bytes of information. My opinion is that maybe it is possible to be created format that is equally comfortable for the machine and for the human. |
|||
![]() |
|
vid
100% agree about pros and cons of each way, just my priorities are apparently different
![]() |
|||
![]() |
|
typedef
@ctl3d32, you can just use SQLLite to keep records.
|
|||
![]() |
|
revolution
typedef wrote: @ctl3d32, you can just use SQLLite to keep records. ![]() |
|||
![]() |
|
ctl3d32
SQLite is too much for me. Too complex.
![]() |
|||
![]() |
|
madmatt
JohnFound wrote: Recently I tend to use binary file formats, as more asm-adequate. This simple transition can save you tons of code lines and to speed up the program (depending on the size of the files processed). If fasm is used to generate the binary file, you would also be able to edit it easily. vid wrote: madmatt: You forgot to include space in your input format string. Should be " %f", in order to skip blanks between numbers (or is this done by default? I don't think so). Not sure about this, ctl3d32 will just have to try it and see. _________________ Gimme a sledge hammer! I'LL FIX IT! |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.