替代 NASM32 中的@data

Alternative to @data in NASM32

我现在正在学习汇编,我意识到符号 @data 没有在 NASM 中定义。这是我的代码:

section .data
    var1 db 0x3
    var2 db 0x4

section .text
global main
main:
    mov eax, @data
    mov ds, eax
    
    mov eax, var1
    mov ebx, var2
    
    mov eax, 0

我在网上搜索替代符号,但没有找到任何东西。那么除了 @data 之外还有其他选择吗?感谢您的帮助。

符号@data在某些汇编器中表示data段首字节的段地址。另请参阅 NASM Chapter 9. Loading segment registers before accessing data is essential in real-mode 16bit programs for DOS or Windows 3. When such program starts, its DS and ES point to Program Segment Prefix structure, not to the data segment of your program. When was the segment declared, assembler also created a relocatable symbol with corresponding name, such as @data or data, which can be used in your program to initialize segment register. Other assemblers may use a different syntax, for instance MOV AX,PARA# [data].

处的 16 位 .EXE 文件示例

当一个flat 32|64位保护模式程序启动时,它的段寄存器已经预加载了Segment Descriptor Table的有效索引,你不必关心关于段寄存器。