zoukankan      html  css  js  c++  java
  • 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里面使用。

  • 相关阅读:
    错误 2 error C2059: 语法错误:“::”
    完全卸载session 所需要的函数
    header("Location:http://www.baidu.com");
    php str_pad() 用法
    php str_pad();
    设计模式系列-01-开篇
    博客园样式的设置系列-01-侧边栏和皮肤的设置
    vs20132015UML系列之-类图
    php获取当前时间和转换格式
    saltstack:multi-master configuration
  • 原文地址:https://www.cnblogs.com/chaoguo1234/p/14619228.html
Copyright © 2011-2022 走看看