Copyright 1996−2017 the NASM Authors – All rights reserved.Redistribution and use in source and binary forms, with or without modification, are permittedprovided that the following conditions are met:
• Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
• Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3.4.1 数字常量
数字类型常量就是一个简单的数字,NASM允许使用不同进制的数字。可以使用以下前缀H
或X
、D
或T
、Q
或O
、B
和Y
,分别表示十六进制(hexadecimal)、十进制(decimal)、八进制(octal)、二进制数(binary)。NASM也支持C语言风格的0x
前缀来表示十六进制数,支持Borland Pascal或Motorola汇编器的风格,使用$
前缀来表示十六进制数。但要注意在NASM中$
有两个功能(见3.1节),因此在表示十六进制数时,$
之后要接数字而不能是字母。此外当前NASM接受前缀0h
表示十六进制数,0d
或0t
表示十进制,0o
或0q
表示八进制,0b
或oy
表示二进制。请注意,与C语言不同单独的前缀0
不能表示八进制常量。
数字常量可以包含_
来分割长数字。
以下例子,实际上会产生相同的代码。
mov ax,200 ; decimal
mov ax,0200 ; still decimal
mov ax,0200d ; explicitly decimal
mov ax,0d200 ; also decimal
mov ax,0c8h ; hex
mov ax,$0c8 ; hex again: the 0 is required
mov ax,0xc8 ; hex yet again
mov ax,0hc8 ; still hex
mov ax,310q ; octal
mov ax,310o ; octal again
mov ax,0o310 ; octal yet again
mov ax,0q310 ; octal yet again
mov ax,11001000b ; binary
mov ax,1100_1000b ; same binary constant
mov ax,1100_1000y ; same binary constant once more
mov ax,0b1100_1000 ; same binary constant yet again
mov ax,0y1100_1000 ; same binary constant yet again