Search code examples
assemblymasmmasm32

How the assembly `dup` operator allocates space for strings and array


I'm reading an assembly language book, where I encountered this line:

Byte 4 dup('stack')        ;20bytes: "stackstackstackstack"

How does this instruction work? How does this instruction allocate space for 4 "stack". How does it do so?


Solution

  • 4 DUP 'stack' just means "4 copies of the string 'stack'".

    for (int i=0; i < 4; ++i) {
        AllocateSpaceFor("stack");
    }