Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `dup (?)` mean in TASM?

Tags:

x86

assembly

tasm

I have this code here, but I'm unfamiliar with the syntax.

STACK16_SIZE    =       100h
stack16         db      STACK16_SIZE dup (?)

I think dup means we declare a variable of type array, as this is a stack, but I'm not sure. So what does dup mean in TASM, exactly?

like image 705
sashoalm Avatar asked Apr 11 '13 18:04

sashoalm


People also ask

What does DUP do in assembly?

The DUP directive tells the assembler to duplicate an expression a given number of times. For example, 4 DUP(2) is equivalent to 2, 2, 2, 2.

What does a DUP operator do?

The DUP operator is very often used in the declaration of arrays This operator works with any of the data allocation directives. the count value sets the number of times to repeat all values within the parentheses.

What is DW in TASM?

"dw" is variable of type WORD, "db" is variable of type BYTE, dd is variable of type double word (int32_t). "?" means the values are not initialized.

What is DUP Masm?

Asking for help, clarification, or responding to other answers.


1 Answers

STACK16_SIZE dup (?) means to duplicate the data in parenthesis by STACK16_SIZE times. It is equivalent to writing ?, ?, ?, ?, ... (100h times)

The data in parens is "uninitialized data". That is, memory is allocated, but not set to any particular value on load.

Assembly does not provide an array "type". If it does, it is only for debuggers for use when inspecting the data. However, in this code snippet, stack16 is a symbol with an address beginning a memory block of bytes—which is counter-intuitive and potentially a source of a subtle bug. For a CPU stack, it really ought to be defined as 16 bit words (dw) or 32 bit words (dd).

like image 115
wallyk Avatar answered Sep 21 '22 13:09

wallyk