NASM中的伪指令
伪指令不是真正的指令,而是为了方便NASM汇编器而存在,但是它们的地位与真正的指令相同:
label: instruction operands ; comment
instruction部分就可以是伪指令
Dx和RESx
Dx声明初始化的数据:
db 0x55 ; just the byte 0x55
db 0x55,0x56,0x57 ; three bytes in succession
db ’a’,0x55 ; character constants are OK
db ’hello’,13,10,’$’ ; so are string constants
dw 0x1234 ; 0x34 0x12
dw ’a’ ; 0x61 0x00 (it’s just a number)
dw ’ab’ ; 0x61 0x62 (character constant)
dw ’abc’ ; 0x61 0x62 0x63 0x00 (string)
dd 0x12345678 ; 0x78 0x56 0x34 0x12
dd 1.234567e20 ; floating-point constant
dq 0x123456789abcdef0 ; eight byte constant
dq 1.234567e20 ; double-precision float
dt 1.234567e20 ; extended-precision float
RESx声明一个未初始化的存储空间,以便在.bss段中出现:
buffer: resb 64 ; reserve 64 bytes
wordvar: resw 1 ; reserve a word realarray
resq 10 ; array of ten reals ymmval:
resy 1 ; one YMM register zmmvals:
resz 32 ; 32 ZMM registers
INCBIN
INCBIN将一个二进制文件包含到输出文件当中:
incbin "file.dat" ; include the whole file
incbin "file.dat",1024 ; skip the first 1024 bytes
incbin "file.dat",1024,512 ; skip the first 1024, and actually include at most 512
EQU
EQU定义一个常量,并且这个常量只在定义的位置被求值一次:
message db ’hello, world’
msglen equ $-message
TIMES
TIMES会将后面的指令重复指定的次数:
zerobuf: times 64 db 0;执行64次db 0
times中的次数除了可以是常量,还可以是表达式:
buffer: db ’hello, world’
times 64-$+buffer db ’ ’ ;补齐64字节
由于NASM在处理了macro之后才会处理times伪指令,因此需要注意是是times伪指令不能在macro里面使用。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了