flat assembler
Message board for the users of flat assembler.
Index
> Main > Make 2 variables share the same address |
Author |
|
CandyMan 16 Jul 2016, 19:15
Code: section '.data' data readable writeable wcStruc WNDCLASS ? virtual at wcStruc wcRaw db sizeof.WNDCLASS dup 0 end virtual _________________ smaller is better |
|||
16 Jul 2016, 19:15 |
|
patulinu 16 Jul 2016, 19:25
CandyMan wrote:
Thank you so much! Now, just out of curiosity: Since all I wanted was initialize the entire structure as raw bytes (and not I can), does the code below do the same or it just initializes the first byte (or field)? Code: wc WNDCLASSEX (0) |
|||
16 Jul 2016, 19:25 |
|
CandyMan 16 Jul 2016, 20:07
see fasmw's EXAMPLES directory
Code: /* struct WNDCLASS style dd ? lpfnWndProc dd ? cbClsExtra dd ? cbWndExtra dd ? hInstance dd ? hIcon dd ? hCursor dd ? hbrBackground dd ? lpszMenuName dd ? lpszClassName dd ? ends */ wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class _________________ smaller is better |
|||
16 Jul 2016, 20:07 |
|
patulinu 16 Jul 2016, 20:31
CandyMan wrote: see fasmw's EXAMPLES directory Yes, I have already done that. The example above illustrates how to initialize a structure field by field. The "virtual" approach, on the other hand, allows me to pre-initialize to zero all those fields I'm not interested in, making easier the job of setting the required fields (by code, as I prefer). In Delphi/Pascal I'm used to the FillChar() function, which doesn't care about the type of the variable. Now I know how to do so in FASM. Thank you again. |
|||
16 Jul 2016, 20:31 |
|
l_inc 17 Jul 2016, 00:26
patulinu
Quote: The "virtual" approach, on the other hand, allows me to pre-initialize to zero all those fields I'm not interested in Firstly, "the virtual approach" in the way shown by CandyMan does not allow you to do anything except for declaring the wcRaw label. The zeroes put into the virtual addressing space have no effect on the content of wcStruc. Secondly, it doesn't make sense to try to initialize the structure with zeroes explicitly, because this is done implicitly anyway. The only difference is the output file size. Thirdly, "the virtual approach" would work the other way around, i.e. if you put the wcRaw array first, and then put wcStruc declaration in a virtual section with its base at wcRaw, but a bit simpler way is to forget about wcRaw and just straightforwardly store zeroes: Code: wcStruc WNDCLASS times sizeof.WNDCLASS store byte 0 at wcStruc+(%-1) But again, this brings nothing, but a (potentially) increased file size. _________________ Faith is a superposition of knowledge and fallacy |
|||
17 Jul 2016, 00:26 |
|
patulinu 17 Jul 2016, 02:19
l_inc wrote:
Thank you for the update. I'm happy to see this forum is a valuable source of knowledge for FASM/Assembler newbies like me. |
|||
17 Jul 2016, 02:19 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.