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. HDU 2191 悼念512汶川大地震

    悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  2. nyist oj 1058 部分和问题 (DFS搜索)

    部分和问题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 给定整数a1.a2........an.推断能否够从中选出若干数,使它们的和恰好为K. 输入 首先,n和k ...

  3. Python 极简教程(一)前言

    现在 Python 用处很多,学的人也很多,其流行程度自不必说.但是很多人学 Python 的时候都遇到过问题,特别对于非计算机专业毕业的人来说. 现在的教程非常多,但是绝大部分对于初学者都不够友好. ...

  4. 【hdu 4333】Revolving Digits

    [链接]http://acm.hdu.edu.cn/showproblem.php?pid=4333 [题意] 就是给你一个数字,然后把最后一个数字放到最前面去,经过几次变换后又回到原数字,问在这些数 ...

  5. 修改tomcat小猫图标,设置项目的favicon图标

    修改tomcat小猫图标,设置项目的favicon图标,方式有两种:全局方式和局部方式 1.全局方式: 进入tomcat服务器\webapps\ROOT,然后用自己项目的favicon.ico替换to ...

  6. oracle学习之路(二)------数组类型/记录类型的使用

    Oracle记录类型介绍 RECORD:用户自己定义数据类型,由单行多列的标量构成的复合数据类型.它将一个或多个标量封装成一个对象进行操作记录不能够总体拿来比較也不能够总体推断为空.能够总体拿来赋值. ...

  7. seaJS注意点:

    1.require 是同步往下执行,require.async 则是异步回调执行.require.async 一般用来加载可延迟异步加载的模块.

  8. 洛谷——P1046 陶陶摘苹果

    https://www.luogu.org/problem/show?pid=1046 题目描述 陶陶家的院子里有一棵苹果树,每到秋天树上就会结出10个苹果.苹果成熟的时候,陶陶就会跑去摘苹果.陶陶有 ...

  9. [D3] Add label text

    If we want to add text to a node or a image // Create container for the images const svgNodes = svg ...

  10. 谈谈vector容器的三种遍历方法

    说明:本文仅供学习交流.转载请标明出处.欢迎转载!          vector容器是最简单的顺序容器,其用法相似于数组.实际上vector的底层实现就是採用动态数组.在编敲代码的过程中.经常会变量 ...