Pregunta

in data segment of assembly codes there are variables without name

string  DB 80
        DB ?
        DB 80 DUP (?)
char    DB 2
        DB ?
        DB 2 DUP (?)

what is the mean codes line 2 & 3 & 5 & 6?

why DB 80 DUP() dont have any name? or in DB 2 DUP ()

this variables dont have name or i think this codes have other usages

because when i remove from sample codes so dont work correctly

i know string and char are array but dont understand other lines mean

¿Fue útil?

Solución

This line...

        DB ?

...means: "Define a byte, and I don't care what it is". The assembler will define a byte there ("allocate space for one byte", if you prefer that phrase) and you take whatever was at that address; probably left over from some other process; it's really who-knows-what

This line...

        DB 80 DUP (?)

...has a similar meaning. The difference is that the 80 DUP part means to duplicate the stunt 80 times.

i.e., the assembler will define (or allocate) a space of 80 bytes there (i.e., at that address in memory; he's keeping a very specific count) and you take whatever was there before (i.e., at those addresses prior to your stuff running) Those bytes are also probably left over who-knows-what bytes from who-knows-how, etc.

This line...

        DB ?

Means the same as the previously described same line; i.e., the assembler will make space at that byte, and you take whatever was left over from before.

Finally, this line...

        DB 2 DUP (?)

Is very similar to the other DUP line you asked about, specifically, instead of defining 80 bytes of who-knows-what, in this case, the assembler will define two bytes there, and when your code runs, you don't know what those two bytes are.

In all liklihood, that's fine, because you'll probably be using those bytes for temporary storage of a string (in the big one) or a 16 bit value (in the small one) or some such thinking.

Do you have an IDE or debugger that you can use to look at that code ? If so, post what you find up here and there is probably someone who whill expound on this to help you understand these concepts further, if I don't get back to you before they do.

So, if this helps, here is the original code, with comments like a pro should write them...

 string  DB 80                 ;Put a single byte with the value of 80 here
         DB ?                  ;Give me a single byte; don't care what it is
         DB 80 DUP (?)         ;Give me 80 bytes here; don't care what they are

 char    DB 2                  ;Put a single byte with the value of 2 here
         DB ?                  ;Give me a byte, I don't care what it is
         DB 2 DUP (?)          ;Give me two bytes here, whatever they are is okay
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top