News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

question about declaring variables

Started by Dasar, September 16, 2006, 10:21:37 AM

Previous topic - Next topic

Dasar

hi

before 2 months ago ( i think ), i have seen a source code (don't remember it now), make declare of variables in the .data & .data? sections.. and also that source has declaration of variables inside the .code section itself..

as i remember it was something like this:

.data

any data

.data?

any data here too

.code

label:

some code

and then something like this

.data
  here he made another declaration for other variables too, and then

.code


and here he continue his code


and final

end label



i tried to do this but i got errors when assembling

he do the same thing every time he needs to declare var(s)

could any one please give me an example about this

thanks in advance :)


PBrennick

Dasar,
Your explanation is not too far off.  For example, remember that there is a big difference in what goes into .data and what goes into .data?.  Data that goes into .data? is uninitialized so you would do something like the following:

MyData dw ?

If you were to put it in the .data section then...

MyData dw 0 ;or 0FFFFh, etc.

in order to give you help of a more specific nature, I need to see your code.  If you do not want to post it here then email it to me.
Paul
The GeneSys Project is available from:
The Repository or My crappy website

Dasar

QuoteFor example, remember that there is a big difference in what goes into .data and what goes into .data?.  Data that goes into .data? is uninitialized so you would do something like the following:

MyData dw ?

If you were to put it in the .data section then...

MyData dw 0 ;or 0FFFFh, etc.

PBrennick thank you very much for your reply :)

yes i know that very well.

i forgot to say that it was in data? section as i remember..

i don't have a specific code to give you, i just ask about something relate to syntax of masm.

but you seems didn't understand my question :)

in short words:

i know that there is a way to declare vars in the code sections, but i forgot how to do that !


hope u understand me now ^_^

if you know how to do this please tell me :)

and thanx again ^_^

PBrennick

I saw that and did not comment on it because it looks correct, I only commented on what was wrong.  Attached is an example that has data in the code section.

Look for Message1, Message2 and Message3.  Remember that even though this data is in the code section it is still global and NOT local.

Paul


[attachment deleted by admin]
The GeneSys Project is available from:
The Repository or My crappy website

Dasar

PBrennick thank you very much for your help :)

raymond

The .data section must be used whenever you have variables which must be initialized, such as an array of specific conversion factors, or a list of messages, or whatever. All those variables declared in the .data section (whether initialized or not) increase the size of your final program.

Any variable which does not need to be initialized should be declared in the .data? section. Regardless of the size of all those variables, they will not increase the size of the final assembled program. The assembler may complain if you try to reserve too much space for those variables.

Here's another way to embed initialized data in your code section. If the total number of bytes for all the initialized data is small, this could effectively reduce the size of the final program because a minimum of 2kb is normally added to the program size even if only a few bytes are in the .data section.

    .... some code
    jmp nextcode
message1 db "Embedded data",0
nextcode:
    .... continue with more code


The only disadvantage of the above is that you cannot generally modify such data if it should become necessary.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

Dasar

raymond, thank you very much for the useful info :)