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