x86 ASM: DD Being Used as an “Instruction”?

2019-08-17 05:12发布

问题:

In the following x86 assembly code:

dd 0x1BADB002
dd 0x00
dd - (0x1BADB002+0x00)

The values don't seem to be assigned to any variables. So what does this snippet of code do? I've heard something about it being stored in memory, but where exactly?

回答1:

dd is a "pseudo-instruction" that assembles 4-byte constants into the output, the same way that add eax,eax assembles 0x01 0xc0 into the output.

The NASM manual section 3.2 Pseudo-Instructions describes db/dw/dd and so on.

In this case, as @MichaelPetch points out, those specific constants are used to assemble a multiboot header into the output file. https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#OS-image-format

How does this assembly bootloader code work?


Related:

How are dw and dd different from db directives for strings?

What is the use of .byte assembler directive in gnu assembly?

x86 assembly - Which variable size to use (db, dw, dd)