Hello people, I have two questions. First, how to create static local and static global variables. Second, how to initialize struct data type like we do in C... st.var1 = 10 Clark
Posted on 2001-06-16 07:29:00 by Superman_San
Static is a high level qualifier. To achieve the same effect in assembly, the data should be kept in a global .DATA? section. When the procedure is again executed, always refer to the same data and don't clear it out once you're complete. That's "static". In C, only the function using the variable can use it, and the rest of the program cannot, or at least, depending on the scope. In Assembly, you have to be sure to only use the variable where it's meant to be used. There is not static in assembly, it's just a global. Just don't use it other places and it'll be the same difference. _Shawn
Posted on 2001-06-16 09:27:00 by _Shawn
How to create static variables? Well... just don't toutch em. I believe you could make a true global static variable by placing it in a read-only segment, but this means it GPF's when you access it. Not a good thing, just define it and leave it. Local variables, by definition (how they are constructed on the stack) CANNOT be truly static. You can't say 'don't toutch the stack here' in the code. Global arrays can be initialized by the compiler like so:

MyArray   STRUCT
  A  DWORD  1
  B  DWORD  2
MyArray   ENDS

Array1  MyArray  {  }   ; uses the above default values
Array2  MyArray  { ,3}  ; uses the above default value for A,
                        ;  changes B to 3
Keep in mind this technique only works for globals. Locals are always created uninitialized, and must have the value set by code. This message was edited by Ernie, on 6/16/2001 9:35:32 AM
Posted on 2001-06-16 09:34:00 by Ernie
Clark Kent, Structures in assembler are always memory operands and the members are moved in and out of registers as memory operands. A structure is basically an array of values in memory, the difference with a structure is that it can have members of different sizes. A STATIC variable in a high level language is constructed from a GLOBAL variable and controlled by the compiler, with an assembler you only have the choice of a GLOBAL variable or a LOCAL variable which is a memory operand on the stack. You use the initialised .DATA section to set a variable to a value, you can also use the uninitialised .DATA? section if you dont want to assign a value to it until you need in code. Regards, hutch@pbq.com.au
Posted on 2001-06-16 09:56:00 by hutch--
Thanks guys, It was real dumb of me to post this question. I guess it takes a little time to think in assembly. Thanks again Clark
Posted on 2001-06-18 00:38:00 by Superman_San
Maybe it's worth mentioning that in real mode, "statics" can go in the code, right alongside the subroutine, provided that they don't grow in load-size at run time. In protected mode this still works for read-only data, provided that the code section is readable, which is normal. (All code sections are readable in Windows 95 and 98, whatever the PE header says.)
Posted on 2001-06-18 01:28:00 by Larry Hammick
"static" in C only means the data is not on the stack. It does not mean constant. C/C++ uses "const" to indicate that data should not change.
Posted on 2001-06-19 20:23:00 by tank