Regarding 8086 assembly's DB and DUP directives

11,817
PRINT_SELECT DB 133 (?)
             DB 123 (?)

in most assemblers is equivalent to

PRINT_SELECT DB 133 DUP(?)
             DB 123 DUP(?)

You may use the 8086 emulator for better understanding for the 8086 assembly.
A sample code that will explain the directives more is shown below.
Once you use the DB 123 (?) , you're basically reserving 123 consecutive bytes (memory locations) in the memory and assigning a NULL value (?) to all of them.

enter image description here

Share:
11,817
saremisona
Author by

saremisona

Updated on July 19, 2022

Comments

  • saremisona
    saremisona almost 2 years

    So I've encountered a problem that made me question my basic understanding of the DB (define byte) and DUP (duplicate) directives. The way I've understood them is:

    • NUM DB 34 will create a variable named NUM and it will assign it with the value 34. Like C char NUM = 34;1
    • NUM DB 34 DUP(?) will give me an array of 34 items, each of them unassigned.
    • NUM DB 3 DUP(4) would give me an array called NUM with 3 items: 4, 4, 4.

    Is this correct?

    In my textbook I encountered:

    PRINT_SELECT DB 133 (?)
                 DB 123 (?)
    

    Is this just a mistake in the textbook, or do these two lines of code mean something else completely?


    Footnote 1: (editor's note): NUM = 34 in asm defines an assemble-time constant not stored in data memory. In MASM-syntax assemblers, it works similarly to a variable in some contexts. But for example mul NUM only works with a memory source, not an immediate, while imul eax, ecx, NUM, or shl ax, NUM, or mov ax, NUM / 2 only works with an immediate, not a memory source.

    • user1703401
      user1703401 almost 7 years
      They are not instructions, they are assembler directives.
    • saremisona
      saremisona almost 7 years
      My mistake :) I apologize.
    • Ped7g
      Ped7g almost 7 years
      NUM = 34 .. not exactly. The db 34 will define single byte with value 34. The NUM is label, pointing to this byte. For example NUM DB 1, 2 will compile as two bytes, and create symbolic label pointing to the first one, it will not do NUM = 1, 2 (whatever would that mean). And there are no variables in assembly. You can think about it like that in some situations, but such view will limit you in fully understanding what that is. And "4, 4, 4, 4" are four items, not three. The lines from book look like typo, it's not valid syntax. If the book has sources with examples, check those.
    • old_timer
      old_timer almost 7 years
      assemble then disassemble and see what each does. not only are these directives but directives as well as assembly language is very specific to the assembler, the program that is being used, no reason to assume that any two 8086 assemblers use the same assembly language or directives, so you need to be a bit more specific next time
    • Cody Gray
      Cody Gray almost 7 years
      Which specific assembler does the textbook cover? MASM? Or something else? As old_timer said, different assemblers use different directives.