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里面使用。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值