Where does the DUP operator continue to count the number?

I need to initialize an array of a structure in the .DATA part of a program. Most are initialized to zero, but I need to adjust the order number. Can I do this in .DATA using the register that holds the DUP statement to initialize the order number of the array elements. Or is there another way to use loops in the .CODE part of a program.

Here is a sample program, when initializing three, each NODEi_KEY must be set to 1..20. The project requires it to be set in the .DATA part, if this is not possible it might be a typo.

.DATA

NODE STRUCT
NODEi_KEY DWORD ?
NODEi_VALUE DWORD 0
NODE ENDS

THREE NODE 20 DUP ({,,})

      

+3


source to share


2 answers


You can do what you want, but you cannot do it with the DUP statement. You will need to use the REPT (repeat) directive and create your own counter:

    .DATA

NODE    STRUCT
    NODEi_KEY DWORD ?
    NODEi_VALUE DWORD 0
NODE    ENDS

THREE   LABEL   NODE
counter = 1
    REPT    20
        NODE    {counter,}
    counter = counter + 1
    ENDM        

      

This creates an array of 20 NODE structures with each NODEi_KEY member initialized to its one-position position in the array.



The REPT directive simply repeats everything up to ENDM as many times as given by the argument. So if you have to change the REPT directive so the argument is only 4, it will generate the following:

    NODE    {counter,}
counter = counter + 1
    NODE    {counter,}
counter = counter + 1
    NODE    {counter,}
counter = counter + 1
    NODE    {counter,}
counter = counter + 1

      

+2


source


While Masm is very flexible and powerful, I don't believe that exactly what you are asking is possible. However, you can absolutely do this:

 array  DB 3 DUP (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19)

      

This is not what you are asking for, but then I donโ€™t believe that you can do what you are asking to do without cutting and pasting or figuring out a way to say DUP

make multiple copies of whatโ€™s inside. What I am above will define three times twenty bytes. Each of these three will have integer values โ€‹โ€‹from 0 to 19 in bytes.



You can also do things like this:

 array DB 3 DUP (4 DUP (1), 2 DUP (2), 4 DUP (8))

      

This defines an area consisting of 3 * 10 bytes that have 1111228888 repeated three times.

+1


source







All Articles