Regarding 8086 assembly's DB and DUP directives
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.
saremisona
Updated on July 19, 2022Comments
-
saremisona almost 2 years
So I've encountered a problem that made me question my basic understanding of the
DB
(define byte) andDUP
(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 Cchar NUM = 34;
1NUM 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 examplemul NUM
only works with a memory source, not an immediate, whileimul eax, ecx, NUM
, orshl ax, NUM
, ormov ax, NUM / 2
only works with an immediate, not a memory source.-
user1703401 almost 7 yearsThey are not instructions, they are assembler directives.
-
saremisona almost 7 yearsMy mistake :) I apologize.
-
Ped7g almost 7 years
NUM = 34
.. not exactly. Thedb 34
will define single byte with value34
. TheNUM
is label, pointing to this byte. For exampleNUM DB 1, 2
will compile as two bytes, and create symbolic label pointing to the first one, it will not doNUM = 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 almost 7 yearsassemble 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 almost 7 yearsWhich specific assembler does the textbook cover? MASM? Or something else? As old_timer said, different assemblers use different directives.