NASM has a simplified syntax designed to let the user code with minimum overhead. In its simplest form, a NASM program needs nothing more than the assembly-language instructions; no assembler directives are necessary. NASM also makes some improvements to the Intel instruction syntax, removing ambiguity and improving consistency. The overall goal is to allow the user, as far as possible, to predict the machine-level opcode of each instruction without referring to the surrounding labels, directives, or instructions.

Source Line

Like most assemblers, NASM supports the standard four-part source line:

label: instruction operands ;comment

Pseudo-Instructions

The following pseudo-instructions cause the assembler to emit data into the output stream:

  • DB – Write bytes (8 bits)
  • DW – Write words (16 bits)
  • DD – Write double words (32 bits)
  • DQ – Write 64-bit floating-point constant
  • DT – Write 80-bit floating-point constant
  • INCBIN – Write the data found in the specified binary data file

These pseudo-instructions cause the assembler to reserve space in the uninitialized data section:

  • RESB - Reserve bytes (8 bits)
  • RESW – Reserve words (16 bits)
  • RESD – Reserve double words (32 bits)
  • RESQ – Reserve space for 64-bit floating-point constants
  • REST – Reserve space for 80-bit floating-point constants

NASM supports the EQU pseudo-instruction, which allows the user to create names for numeric constants.

Finally, NASM offers the TIMES prefix for all instructions and pseudo-instructions. The TIMES prefix causes NASM to repeat the associated instruction a specified number of times.

Labels

Any NASM instruction or pseudo-instruction may have a corresponding label. In NASM, labels are numeric constants equal to the instruction's location in memory. They are virtually identical to constants defined with EQU, and may be used in the same way. This is a key difference from other assemblers, where labels contain additional information about the type of the pointed-to data. By treating labels as simple numeric constants, NASM vastly simplifies its instruction syntax, as discussed in the next section.

NASM also supports a local-label mechanism. This system prevents naming conflicts by allowing labels of the same name to exist in different contexts. Label names beginning with a dot (.) become "local" to the last non-local label NASM sees. The label remains valid until the next non-local label comes along, at which point NASM resets the list of local labels. This allows the user to re-use short label names such as ".else" or ".loop" in multiple places without naming conflicts.

To support macros, NASM supports a third kind of label beginning with "..@". These labels have non-local scope, but do not reset the list of local labels.

Addressing

NASM has a simple rule for dealing with memory addressing in instructions: Everything in square brackets is a reference to a memory address, while everything outside of square brackets is a constant. For example:

data: dd 1234

mov ebx, data

mov eax, [data]

When this code finishes executing, the register ebx will contain the memory address of the data, while eax will contain the contents of that memory address, namely the number 1234. This is different from other assemblers such as MASM, where the first instruction might act like the second instruction depending on the type of label. NASM's syntax is much more consistent in this regard.

Doc

See [http://www.tortall.net/projects/yasm/manual/html/nasm.html Part I, NASM Syntax] of the Yasm User Manual. It's also available in PDF, see Yasm documentation.

SRC=https://github.com/yasm/yasm/wiki/NasmSyntax

NASM Syntax的更多相关文章

  1. GAS Syntax

    GAS or GNU as syntax is a different form of syntax for assembly language files, known also as AT& ...

  2. asm 32 /64

    我使用NASM编写的,运行在32位windows和linux主机上,但后来需求增加了,需要在64位windows和linux上运行,windows自身有个wow(windows on windows) ...

  3. Yasm 1.3.0 Release Notes

    Yasm 1.3.0 Release Notes http://yasm.tortall.net/releases/Release1.3.0.html Target Audience Welcome ...

  4. bsdasm

    bsdasm 来源 http://www.int80h.org/bsdasm/ Preface by G. Adam StanislavWhiz Kid Technomagic Assembly la ...

  5. YASM User Manual

    This document is the user manual for the Yasm assembler. It is intended as both an introduction and ...

  6. NASM mode for Emacs

    NASM mode for Emacs   Quick post for those Emacs users out there.   The common assembler used on GNU ...

  7. 如何在Open Live Writer(OLW)中使用precode代码高亮Syntax Highlighter

    早先Microsotf的Windows Live Writer(WLW)现在已经开源了,并且更名为Open Live Writer,但是现在Windows Live Writer还是可以现在,Open ...

  8. Linix登录报"/etc/profile: line 11: syntax error near unexpected token `$'{\r''"

    同事反馈他在一测试服务器(CentOS Linux release 7.2.1511)上修改了/etc/profile文件后,使用source命令不能生效,让我帮忙看看,结果使用SecureCRT一登 ...

  9. 获取文件的缩略图Thumbnail和通过 AQS - Advanced Query Syntax 搜索本地文件

    演示如何获取文件的缩略图 FileSystem/ThumbnailAccess.xaml <Page x:Class="XamlDemo.FileSystem.ThumbnailAcc ...

随机推荐

  1. JS错误记录 - dom操作 - 排序

    本次练习错误总结: 1. for循环要套到按钮的onclick里面,否则onclick点击事件无法依次执行. 2. var n1, var n2 这两个变量是arr.sort排序使用的,所以应该放在s ...

  2. LuoguP2764 最小路径覆盖问题(最大流)

    题目描述 «问题描述: 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开 ...

  3. 搭建并配置本地GitLab服务器教程

    由于工作单位不一定能够方便使用外部网络,现以下载rpm包来搭建一套本地GitLab服务器. 1. 系统准备 系统:redhat 7.3 2. 下载所需安装包 去官网下rpm包,下载地址,ce是免费的社 ...

  4. 【Material Design视觉设计语言】应用样式设计

    作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells Github:https://github.co ...

  5. VMware虚拟机XP系统安装

    转载:http://jingyan.baidu.com/article/54b6b9c00e2f452d593b4762.html

  6. C语言编程入门——程序练习(下)

    C语言的一些简单操作练习. 互换两个数字: # include <stdio.h> int main(void) { int i = 3; int j = 5; int t;   //将i ...

  7. 从头认识java-15.7 Map(4)-介绍HashMap的工作原理-hash碰撞(常常作为面试题)

    这一章节我们来讨论一下hash碰撞. 1.什么是hash碰撞? 就是两个对象的key的hashcode是一样的,这个时候怎么get他的value呢? 答案是通过equals遍历table那个位置上面的 ...

  8. MariaDB 安装 (YUM)

    在CentOS 7.0安装MariaDB的数据库,在这里记录下安装过程,以便以后查看. 1. 安装MariaDB 安装命令 yum -y install mariadb mariadb-server ...

  9. go 语言学习笔记 0001 --> iota

    go语言中预置了一个预定义常量 iota 这个东西有个很奇怪的特性,会根据 const 关键字改变值 默认的,iota在const出现的时候会初始化为0,而后不断递加1,直到出现第二个const关键字 ...

  10. hibernate中的事务管理是怎么概念?

    1.JDBC事务 JDBC 事务是用 Connection 对象控制的.JDBC Connection 接口( java.sql.Connection )提供了两种事务模式:自动提交和手工提交. ja ...