【发布时间】:2021-12-30 16:47:21
【问题描述】:
我想计算对齐的地址。 'label' 应该对齐 4 字节边界。
bits 32
mov eax, label
end: ; here is the end of program
align 4
label:
这个 nasm 代码输出 8 个字节。
$ nasm -f bin test.nasm -o test.o
$ ndisasm -o 0x0 -b 32 test.o
00000000 B808000000 mov eax,0x8
00000005 90 nop
00000006 90 nop
00000007 90 nop
但实际上程序大小是 5 个字节。 是否可以在不扩展程序大小的情况下定义标签? 我希望将“标签”定义为值 8,并且 test.o 的文件大小将为 5。
我也尝试使用 '$' 变量来计算地址,如下所示。
bits 32
mov eax, label
end: ; here is the end of program
label equ ( ($+3) & ~3 )
但是 nasm 不接受这种表达方式。
$ nasm -f bin test.nasm -o test.o
test.nasm:4: error: `&' operator may only be applied to scalar values
【问题讨论】:
标签: assembly x86 nasm memory-alignment