Search code examples
assemblyx86masm

source BYTE "This is the source string",0 target BYTE SIZEOF source DUP(0),0


What is SIZEOF referring to? Is it referring to the size of the source (lengthOf * TYPE which is equal to number of elements in the array * the size of each element)? Also, can someone explain DUP(0),0? This is referring to Assembly x86 MASM. Thank you


Solution

  • SIZEOF simply denotes the size of a type or structure.

    It refers to whatever you put after the SIZEOF keyword.

    SIZEOF element     ; refers to a single element in the array.  
    SIZEOF wholearray  ; sizeof(element) * number_of_elements_in_array.
    

    Because it is resolved at compile-time it will only work if the size of an array is static.

    The syntax for DUP is:

    count DUP (initialvalue [[, initialvalue]]...)
    
    10 DUP (0)        ; 10 zero's
    2 DUP (3 DUP ("A"), "BC")  ; "AAABCAAABC"
    

    First you get a repeat count, then the keyword DUP and then a specification of what to repeat in brackets.
    The repeat spec may include additional DUP statements.