flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
system error 09 Oct 2017, 01:45
#3
buff db 1000 dup(0) 1000 = size dup(0) = initializers |
|||
![]() |
|
jorido 09 Oct 2017, 02:34
system error wrote: #3 how come, say "buff db 100" allocates a single byte and puts value "100" in it and "buff db 100 dup(0)" allocates 100 bytes? that is, they have the same part buff db 100 in common but do different things[/b] |
|||
![]() |
|
revolution 09 Oct 2017, 04:17
The first option with times gives a slightly different result because there is no size attached to the buff variable.
Code: buff: db ? mov [buff],0xff ;<--- error operand size not specified Code: buff db ? mov [buff],0xff ;<-- okay |
|||
![]() |
|
Tomasz Grysztar 09 Oct 2017, 07:07
jorido wrote: how come, say |
|||
![]() |
|
jorido 09 Oct 2017, 09:37
Ok.
"buff db 100" and "buff db 100 dup(0)" indeed do different things: allocating single byte with value 100 and 100 bytes with zeroes, right? |
|||
![]() |
|
system error 09 Oct 2017, 19:37
jorido wrote: Ok. Right. One more little step to make it easier for you is to use a constant MAXSIZE = 1000 xdata TIMES MAXSIZE db 0 xdata rb MAXSIZE xdata db MAXSIZE dup(0) You show some genuine efforts, we give you help some more ![]() |
|||
![]() |
|
Furs 09 Oct 2017, 20:47
jorido wrote: how come, say ![]() Sadly, "buf times 100 db 0" is not valid... you should use a macro to get rid of this stupid syntax. |
|||
![]() |
|
jorido 11 Oct 2017, 13:42
Are
Code: buff rb 1000 buff db 1000 dup(0) exactly the same? |
|||
![]() |
|
revolution 11 Oct 2017, 13:48
jorido wrote: Are The first is uninitialised. In some file formats the data is not included in the executable, only its size is given. The second has explicit initialisation of all 0's. The executable will contain every one of those zero bytes. |
|||
![]() |
|
Furs 11 Oct 2017, 14:11
Note that "uninitialized" means also zero-ed (by the OS) on load on most platforms (Linux, Windows, etc), so there's no point in using dup(0) at all. It will only waste space on disk for no gain.
If you want something zero-initialized use rb since it saves space on disk and is otherwise "the same" functionally, unless the target OS doesn't zero-initialize data (DOS maybe? idk). |
|||
![]() |
|
jorido 12 Oct 2017, 01:00
but when I compile it using first buff rb 1000 and then buff db 1000 dup(0), the sizes, in bytes, of output files are identical
|
|||
![]() |
|
revolution 12 Oct 2017, 01:40
It depends on the layout of the code. If you are using a PE file for example then if you have initialised values following uninitialised space then the uninitialised will still be included.
Code: format pe .. section ... uninit rb 1000 inited db 'a' ;<--- this value will force all preceding values to be inclucded Code: format pe .. section ... inited db 'a' uninit rb 1000 ;<--- this won't be included in the output file. |
|||
![]() |
|
jorido 12 Oct 2017, 14:16
linux, x64
or did Furs mean only if I initialize an array but don't actually use it at all? |
|||
![]() |
|
Furs 12 Oct 2017, 15:37
I'm not sure I understand the question, but...
Initialization means that the value of that buffer will be the given value on entry to the program. 'rb' reserves bytes, but those bytes are initialized to zero on Linux/Windows, without taking space on disk. So when at your program's entry point, they'll be zeros. It's like allocating a block of memory containing all your 'rb' stuff and then zero-ing them in a loop before your program's entry point is even executed. (that's what the OS does) If you used 'db' instead, it would copy them from the disk to the memory block instead of zeroing it, thus if data is zeros, it would waste it on the disk for no reason, since it ends up being zeros in memory anyway. Note that, as revolution said, you shouldn't mix db with rb in same section/segment. Just put all 'rb' in their separate section/segment. |
|||
![]() |
|
revolution 13 Oct 2017, 00:18
Furs wrote: Note that, as revolution said, you shouldn't mix db with rb in same section/segment. Just put all 'rb' in their separate section/segment. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.