flat assembler
Message board for the users of flat assembler.
Index
> Main > Arrays in FASM |
Author |
|
Killswitch 03 Dec 2007, 13:51
Hey,
How do you create an array of bytes with 30,000 elements in FASM? Cheers |
|||
03 Dec 2007, 13:51 |
|
vid 03 Dec 2007, 14:33
Code:
buf rb 30000
|
|||
03 Dec 2007, 14:33 |
|
vid 03 Dec 2007, 14:56
edfed: why would you store size of array in first dword? What for? It is compile time constant 30000, no need to save it in variable.
|
|||
03 Dec 2007, 14:56 |
|
edfed 03 Dec 2007, 15:02
first dword is a tag, a label, or else...usefull for memory management.
if the array is accessed with a ptr, if many arrays are defined for the same routine, you need to have the size value defined in memory, not only equates. to resize the array too. obtain an overview of the array by the dword size, etc etc... accessing an array force to add 4 to the pointer. |
|||
03 Dec 2007, 15:02 |
|
LocoDelAssembly 03 Dec 2007, 15:34
No anymore
Code: dd @f-array ; size of the array array: rb 30000 ;array @@: ;anonymous label, only for size purpose Now you access its size from array-4 so the user don't worry about anything and the memory handling routines access the "secret" size field. |
|||
03 Dec 2007, 15:34 |
|
edfed 03 Dec 2007, 16:10
it's a good idea, but no..
the array is complete when it's size is inside. array is a file, a file must be easylly stored/loaded on disk/memory, it's label, "array", is for the full array, size and other field included. as you want... now, killswich, you have many possibilities. note: if we want to make a "standard" fasm array definition, to easy share code, link it etc... we need to find a consensus. who is for size inside array? who is for size outside array? who is for else? what about aditional fields? Code: array: dd @f-$-4 ;size of dim field, 32bits rd Ndim @@: dd @f-$-4 ;size of full array,32bits rb ? ;array, can be in bytes, words dwords, as you want @@: user shall respect a minimum coding constraints in ASM! if they want easy and fast coding ways, they just have to choose an other programming language. personnaly, i always use this method to define arrays. and it works very well in adition to array, i "always" create an equate field. Code: mov esi,array call arrayexplorer ... arrayexplorer: push esi ;save current array... mov edx,[esi+array.size] ;how many dimensions*4? add esi,[array.dims] mov ecx,[esi+edx] ;how many bytes in array? add esi,edx add esi,[array.array] ;now esi point to array. ... xxx [esi+?],x xxx x,[esi+?] ... pop esi ;returns array ret array: .size=0 .dims=4 ;same .array=4 dd @f-$-4 rd Ndim @@: dd @f-$-4 rb ? @@: i know it's not a very beautyfull code, but it's simple to write.. |
|||
03 Dec 2007, 16:10 |
|
bitRAKE 03 Dec 2007, 17:21
LocoDelAssembly wrote: No anymore Code: mov ecx,[esi-4] .1: cmp byte [esi+ecx],80h je DoSomething dec ecx jns .1 |
|||
03 Dec 2007, 17:21 |
|
vid 03 Dec 2007, 17:42
edfed: Yes, size of array in dword before array might be useful for generic routines that work with array. But that is only in case you decide to design your code for such (custom) style. It is one of many possibilities for type-safe(r) programming.
But why the hell do you put it as answer to "how to declare array in FASM"? You are just overcomplicating very simple stuff by adding your custom constructs to it as if it was default, normal and/or required way. Your code example is NOT an array. It is some higher level wrapper for array. Please do not confuse newcomers by adding your own complexity to it. |
|||
03 Dec 2007, 17:42 |
|
edfed 03 Dec 2007, 18:00
ok, but i want to know, why do you always contradict everybody?
to force them to reflect more? or simply because like me, you cannot accept datas from others? all in all, i agree with you for all that you say, but i agree with me. my custom array structure is to use in file systems, memory allocations, 3d universes, window( not MSwindows) structures, and 2d Sonic the hedgehogg levels if i code one. but yes, simply defining array as a string of bytes, without any custom structure is possible and better for some static case, like a codepage for keyboard, a fixed size font, etc... |
|||
03 Dec 2007, 18:00 |
|
vid 03 Dec 2007, 18:54
edfed: in this particular case, i already told you reason. I think answer to his question was as simple as one line, and I think your extra info (which he didn't ask for) only confused him. And this isn't first time, something like that happened.
If you would write "this is my own wrapper structure for array, which I think is very useful", then it would be fine. But this time it appears, especially to someone new, that what you write is way to create arrays in ASM. Rule of thumb: only answer what people ask you about. I am pretty sure that he didn't want to hear about paging or segment descriptors. about "arguing with everyone": i think people should strive to be as good as possible. If I believe someone is wrong, I feel it as my duty to correct mistake. Yes, it might be annoying, but in the end, either he or I learn something new, and that's good, even if I become asshole in people's eyes. |
|||
03 Dec 2007, 18:54 |
|
edfed 03 Dec 2007, 19:08
exactlly what i think.
it's a little confusing for newbee, but at least, he/she will see that the difference between simple array and complex array is minimal, as just some ptr. i'm sorry! i've made a big mistake by reply 3211244 lines for this very simple question. knowledge is like butter, the less you have, the more you spread it. |
|||
03 Dec 2007, 19:08 |
|
vid 03 Dec 2007, 19:20
Quote: i'm sorry! i've made a big mistake by reply 3211244 lines for this very simple question. It would be fine, if you wrote that it is just an extra option, not "this is an array". Anyway, screw this, we both understand now. |
|||
03 Dec 2007, 19:20 |
|
bitRAKE 03 Dec 2007, 19:54
I like the way discussions evolve to expand on a topic. So, if one were to search the board for "array" then several implementations and ideas about arrays can be explored. Often I search in just such a manner and am thankful others are able to share their discovery and the time they have taken to do so.
|
|||
03 Dec 2007, 19:54 |
|
edfed 03 Dec 2007, 20:03
by this way, we (all active fasm forumers) will forcelly arrive to a very good asm reference programming guide, and possibly a FASMOS will born, one day.
|
|||
03 Dec 2007, 20:03 |
|
Hayden 07 Dec 2007, 11:20
at the end of the day an array is just a string of 1s and 0s, nothing more, nothing less!
_________________ New User.. Hayden McKay. |
|||
07 Dec 2007, 11:20 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.