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

  • 相关阅读:
    BizTalk2010简介
    各大类库的类工厂
    全国城市三级级联菜单(java+Ajax+jQuery)
    gcc编译系统
    通用排行榜组件
    本地化中文示例代码需求调查
    PortalBasic Java Web 应用开发框架(源码、示例及文档)
    FFLIB 框架
    ORM/IOC框架设计感悟
    个人日记
  • 原文地址:https://www.cnblogs.com/chaoguo1234/p/14619228.html
Copyright © 2020-2023  润新知