Share to: share facebook share twitter share wa share telegram print page

Netwide Assembler

Netwide Assembler
NASM logo
原作者Simon Tatham, Julian Hall
開發者H. Peter Anvin, et al.
当前版本
  • 2.16.03 (2024年4月17日;穩定版本)[1]
編輯維基數據鏈接
源代码库 編輯維基數據鏈接
操作系统Windows, Unix-like, OS/2, MS-DOS
语言English
类型x86 assembler
许可协议BSD 2-clause
网站www.nasm.us

Netwide Assembler (简称 NASM)是一款基于英特尔 x86 架构的汇编与反汇编工具。它可以用来编写 16位32位IA-32)和 64位x86-64)的程序。 NASM 被认为是 Linux 平台上最受欢迎的汇编工具之一。[2]

NASM 最初是在朱利安·霍尔的协助下由西蒙·泰瑟姆开发的。 截至2016年 (2016-Missing required parameter 1=month!),它被一个由 H.Peter Anvin 领导的小团队所维护。[3] 它是一款基于简化版(二句版)BSD许可证开放源代码软件[4]

功能

NASM 可以输出包括 COFF、OMF、a.out、可执行与可链接格式(ELF)、Mach-O 和二进制文件(.bin,二进制磁盘映像,用于编译操作系统)等多种二进制格式,而地址无关代码仅支持 ELF 对象文件。 NASM 也有自己的二進位格式,稱為 RDOFF。[5]

输出格式的广泛性允许将程序重定向到任何 x86 操作系统(OS)。 此外,NASM 可以创建浮动二进制文件,它可用于写入引导加载程序、只读存储器(ROM)映像以及操作系统开发的各个方面。 NASM 可以作为交叉汇编程序(如 PowerPC 和 SPARC)在非 x86 平台上运行,尽管它不能生成这些机器可用的程序。

NASM 使用英特尔汇编语法的变体而不是 AT&T 语法(GNU 汇编器采用的语法)。 [6]它还避免了 MASM 和兼容汇编器使用的自动生成區段覆盖(以及相关的 ASSUME 指令)等功能。

用于各种操作系统的示例程序

这是一个 DOS 操作系统下的 "Hello world!" 程序

section .text
org 0x100
	mov	ah, 0x9
	mov	dx, hello
	int	0x21

	mov	ax, 0x4c00
	int	0x21

section .data
hello:	db 'Hello, world!', 13, 10, '$'

一个类似程序在 Microsoft Windows 下的示例:

global _main
extern _MessageBoxA@16
extern _ExitProcess@4

section code use32 class=code
_main:
	push	dword 0      ; UINT uType = MB_OK
	push	dword title  ; LPCSTR lpCaption
	push	dword banner ; LPCSTR lpText
	push	dword 0      ; HWND hWnd = NULL
	call	_MessageBoxA@16

	push	dword 0      ; UINT uExitCode
	call	_ExitProcess@4

section data use32 class=data
	banner:	db 'Hello, world!', 0
	title:	db 'Hello', 0

一段 Linux 下的等价程序:

global _start

section .text
_start:
	mov	eax, 4 ; write
	mov	ebx, 1 ; stdout
	mov	ecx, msg
	mov	edx, msg.len
	int	0x80   ; write(stdout, msg, strlen(msg));

	mov	eax, 1 ; exit
	mov	ebx, 0
	int	0x80   ; exit(0)

section .data
msg:	db	"Hello, world!", 10
.len:	equ	$ - msg

下面是一个用于苹果 macOS(原為 OS X)的 64 位元程序,用于输入按键并将其显示在屏幕上:

global _start

section .data

	query_string:		db	"Enter a character:  "
	query_string_len:	equ	$ - query_string
	out_string:			db	"You have input:  "
	out_string_len:		equ	$ - out_string

section .bss

	in_char:			resw 4

section .text

_start:

	mov	rax, 0x2000004	 	; put the write-system-call-code into register rax
	mov	rdi, 1				; tell kernel to use stdout
	mov	rsi, query_string	; rsi is where the kernel expects to find the address of the message
	mov	rdx, query_string_len	; and rdx is where the kernel expects to find the length of the message 
	syscall

	; read in the character
	mov	rax, 0x2000003		; read system call
	mov	rdi, 0				; stdin
	mov	rsi, in_char		; address for storage, declared in section .bss
	mov	rdx, 2				; get 2 bytes from the kernel's buffer (one for the carriage return)
	syscall

	; show user the output
	mov	rax, 0x2000004		; write system call
	mov	rdi, 1				; stdout
	mov	rsi, out_string
	mov	rdx, out_string_len
	syscall

	mov	rax, 0x2000004		; write system call
	mov	rdi, 1				; stdout
	mov	rsi, in_char
	mov	rdx, 2				; the second byte is to apply the carriage return expected in the string
	syscall

	; exit system call
	mov	rax, 0x2000001		; exit system call
        xor     rdi, rdi
	syscall

链接

NASM 主要输出目标文件(扩展名一般为 .obj),这些目标文件通常不能自行执行。唯一的例外是浮动二进制文件(例如 .COM) ,它们在现代使用中固有地受到限制。 要将目标文件转换为可执行程序,必须使用适当的链接程序,例如用于 Windows 的 Visual Studio“LINK”实用程序或用于类 Unix 系统的 ld。

发展

第一版(版本号0.90)发布于1996年10月。[7]

2007年11月28日,2.00版本发布,增加对 x86-64 扩展的支持。 开发版本不再上传到 SourceForge.net;相反,它们会被检入到项目自己的 Git 存储库中,而其二进制程序的快照可在项目官网上找到。

一个用于 NASM 文档的搜索引擎也已可用。[8]

截至 2.07 版本,NASM 在简化 BSD 许可证(二句版)下发布。

RDOFF

RDOFF
开发者Julian Hall
格式类型Object file format
作为容器Object code

开发人员使用可重定位的动态对象文件格式(RDOFF)来测试 NASM 的目标文件输出能力的完整性。它很大程度上基于 NASM 的内部结构,[9]主要由一个头部组成,头部包含输出驱动程序函数调用的序列化,后跟包含可执行代码或数据的部分数组。 NASM 发行版中包含了使用该格式的工具,包括链接程序 (linker) 和加载程序 (loader)。

直到1996年10月发布 0.90 版,NASM 才支持只输出浮动格式的可执行文件(例如 DOS 的 COM 文件)。在版本 0.90 中,Simon Tatham 增加了对一个目标文件输出接口的支持,并且只支持用于 16 位元代码的 DOS 的 .OBJ 文件。[10]

NASM 因此缺少一个 32 位元的对象格式。 为了解决这个问题,作为学习对象文件接口的练习,开发人员朱利安·霍尔将第一版 RDOFF 发布于 NASM 0.91 版本。

自从这个初始版本以来,对 RDOFF 格式进行了一次重大更新,它在每个标题记录上增加了一个记录长度指示器,[11] 允许程序跳过它们无法识别格式的记录,并支持多个區段;RDOFF1 仅支持三個區段:文本,数据和 bss(包含未初始化的数据)。

另请参见

参考文献

  1. ^ Release 2.16.03. 2024年4月17日 [2024年4月23日]. 
  2. ^ Ram Narayan. Linux assemblers: A comparison of GAS and NASM. [2018-03-29]. (原始内容存档于2013-10-03). two of the most popular assemblers for Linux, GNU Assembler (GAS) and Netwide Assembler (NASM) 
  3. ^ The Netwide Assembler. [2008-06-27]. (原始内容存档于2008-07-24). 
  4. ^ NASM Version History. [2009-07-19]. (原始内容存档于2009-07-04). 
  5. ^ NASM Manual. [2009-08-15]. (原始内容存档于2009-02-23). 
  6. ^ Randall Hyde. NASM: The Netwide Assembler. [2008-06-27]. (原始内容存档于2010-09-12). 
  7. ^ NASM Version History. [2017-04-23]. (原始内容存档于2017-05-01). 
  8. ^ NASM Doc Search Engine. [2009-09-14]. (原始内容存档于2010-01-23). 
  9. ^ NASM Manual Ch. 6. [2008-06-27]. (原始内容存档于2008-07-24). 
  10. ^ NASM CVS. 2008-06-08 [2008-06-27]. (原始内容存档于2022-04-07). 
  11. ^ V1-V2.txt. 2002-12-04 [2008-06-27]. (原始内容存档于2022-04-07). 

进一步阅读

外部链接

Read other articles:

الألعاب الأولمبية الشتوية 1984 ملعب عاصم فرهادوفيتش هاسا،  وسكندريجا  [لغات أخرى]‏،  وياهورينا،  وإيجمان ، جمهورية يوغوسلافيا الاشتراكية الاتحادية  الرياضيون المشاركون 49 [1]،  و1272 [1]  انطلاق الألعاب 8 فبراير 1984  الاختتام 19 فبراير 1984  المو

Переписна місцевість Лорелсангл. Laureles Координати 26°06′47″ пн. ш. 97°29′21″ зх. д. / 26.11330000002777751° пн. ш. 97.48940000002778561° зх. д. / 26.11330000002777751; -97.48940000002778561Координати: 26°06′47″ пн. ш. 97°29′21″ зх. д. / 26.11330000002777751° пн. ш. 97.48940000002778561° …

Island in the Houtman Abrolhos, off the coast of Mid West Western Australia North IslandAerial photograph of the southern half of North Island, looking westGeographyLocationIndian Ocean, off the coast of Western AustraliaCoordinates28°18′9″S 113°35′41″E / 28.30250°S 113.59472°E / -28.30250; 113.59472[1]ArchipelagoHoutman AbrolhosArea180 ha (440 acres)Length2 km (1.2 mi)Width1.5 km (0.93 mi)Highest elevation13 m (43…

Yeimy Paola Vargas Información personalNacimiento 16 de junio de 1983 (40 años)Cartagena de Indias, Bolívar, ColombiaNacionalidad ColombianaCaracterísticas físicasAltura 1,83 m (6′ 0″)Medidas 85-62-92Ojos CafésCabello CastañoEducaciónEducada en Universidad de San Buenaventura Información profesionalOcupación Actriz y modelo[editar datos en Wikidata] Yeimy Paola Vargas Gómez (Cartagena de Indias, Bolívar, Colombia, 16 de junio de 1983) es una actriz, modelo y ex-rei…

弗拉姆海峽是北冰洋的海峽,連接北冰洋、格陵蘭海和挪威海,平均水深2,000米,最大水深2,600米,表面海水溫度在過去一個世紀上升1.9攝氏度。 外部連結 Daily Satellite Picture[永久失效連結] 坐标:80°0′N 2°0′W / 80.000°N 2.000°W / 80.000; -2.000 这是一篇格陵兰地理小作品。你可以通过编辑或修订扩充其内容。查论编 这是一篇挪威地理小作品。你可以通过编辑…

Artikel ini sebatang kara, artinya tidak ada artikel lain yang memiliki pranala balik ke halaman ini.Bantulah menambah pranala ke artikel ini dari artikel yang berhubungan atau coba peralatan pencari pranala.Tag ini diberikan pada Februari 2023. Artikel ini tidak memiliki referensi atau sumber tepercaya sehingga isinya tidak bisa dipastikan. Tolong bantu perbaiki artikel ini dengan menambahkan referensi yang layak. Tulisan tanpa sumber dapat dipertanyakan dan dihapus sewaktu-waktu.Cari sumber:&#…

For Glenn Dale in Maryland, see Glenn Dale, Maryland. Town in West VirginiaGlen Dale, West VirginiaTown FlagSealMotto: Montani Semper LiberiLocation of Glen Dale in Marshall County, West Virginia.Coordinates: 39°56′55″N 80°45′18″W / 39.94861°N 80.75500°W / 39.94861; -80.75500Country United StatesState West VirginiaCounty MarshallArea[1] • Total1.20 sq mi (3.11 km2) • Land0.85 sq mi (2.20&#…

Masjid Alâeddin SinopAlâeddin Sinop CamiiAgamaAfiliasi agamaIslam – SunniProvinsiSinopLokasiLokasiSinopNegara TurkiKoordinat42°1′24″N 35°8′33″E / 42.02333°N 35.14250°E / 42.02333; 35.14250Koordinat: 42°1′24″N 35°8′33″E / 42.02333°N 35.14250°E / 42.02333; 35.14250ArsitekturJenisMasjidGaya arsitekturTurki dengan sedikit sentuhan arsitektur SeljukDidirikan1220SpesifikasiKubah5Menara1 Masjid Alâeddin Sinop (bahasa Turk…

Dieser Artikel erläutert die historische österreichisch-ungarische Reederei; das gleichnamige, heute tätige Unternehmen wird unter Österreichischer Lloyd Seereederei erläutert. Österreichischer Lloyd Logo Rechtsform Aktiengesellschaft Gründung 1833 (Reederei: 1836) Auflösung 1921 Auflösungsgrund Übergang auf den italienischen Staat Fortführung bis 2006 als Lloyd Triestino Sitz Triest Branche Informationsbeschaffung Reederei Verlag und Druckerei Dampfer Bohemia (um 1910) Der Dampfer Gr…

Aim to improve perceived human genetic quality For the album, see Eugenics (album). For the study of human improvement via social conditions, see euthenics. A 1930s exhibit by the Eugenics Society. Two of the signs read Healthy and Unhealthy Families and Heredity as the Basis of Efficiency. Part of a series onDiscrimination Forms Institutional Structural Attributes Age Caste Class Dialect Disability Genetic Hair texture Height Language Looks Mental disorder Race / Ethnicity Skin color S…

President of theInternational Criminal CourtIncumbentPiotr Hofmańskisince March 11, 2021 (2021-03-11)SeatThe HagueAppointerJudges of the ICCTerm lengthThree yearsrenewable onceConstituting instrumentRome Statute of the International Criminal CourtFormation2003First holderPhilippe KirschWebsiteThe Presidency The Presidency of the International Criminal Court is the organ responsible for the proper administration of the Court (apart from the Office of the Prosecutor).[1 …

Protected area in the U.S. states of Wyoming, Idaho, and Utah Caribou–Targhee National ForestCamas flowers and the west vista of the Teton Range from Caribou–Targhee National ForestLocationIdaho-Wyoming-Utah, United StatesNearest cityPocatello, IDCoordinates42°47′0″N 111°33′0″W / 42.78333°N 111.55000°W / 42.78333; -111.55000Area2,630,716 acres (10,646.13 km2)[1]Established1903Governing bodyU.S. Forest ServiceWebsiteCaribou–Targhee …

Interjections in the English language Part of a series onEnglish grammar MorphologyPluralsPrefixes (in English)Suffixes (frequentative) Word typesAcronymsAdjectivesAdverbs (flat)ArticlesCoordinatorsCompoundsDemonstrativesDeterminers (List here)ExpletivesIntensifierInterjectionsInterrogativesNounsPortmanteausPossessivesPrepositions (List here)Pronouns (case · person)SubordinatorsVerbs VerbsAuxiliary verbsMood (conditional · imperative · subjunctive)Aspect (continuous · habitual · perfect)-in…

Podomoro City pada tahun 2012 Podomoro City adalah sebuah superblok terpadu yang terletak di Grogol Petamburan, Jakarta Barat. Kompleks terintegrasi dengan luas sekitar 22 hektar ini berisi 11 menara residensial, 2 pusat perbelanjaan, satu menara perkantoran, satu kompleks pertokoan, dan satu hotel bintang lima.[1][2] Superblok ini dikembangkan oleh Agung Podomoro Land. Selain Central Park Jakarta, di kompleks ini juga ada NEO SOHO,[3] Podomoro University, dan kompleks pe…

Body of papyri from Graeco-Roman Egypt Greek Magical PapyriThe Egyptian god Set seen on the papyri.Created100s BCE to 400s CEAuthor(s)VariousMedia typePapyriSubjectMagical spells, formulae, hymns, and rituals The Greek Magical Papyri (Latin: Papyri Graecae Magicae, abbreviated PGM) is the name given by scholars to a body of papyri from Graeco-Roman Egypt, written mostly in ancient Greek (but also in Old Coptic, Demotic, etc.), which each contain a number of magical spells, formulae, hymns, and r…

село Околена Країна  Україна Область Чернівецька область Район Вижницький район Громада Усть-Путильська сільська громада Код КАТОТТГ UA73020170060017624 Основні дані Населення 104 Поштовий індекс 59111 Телефонний код +380 3738 Географічні дані Географічні координати 48°09′34″ пн. …

Indian politician Dr.Paramasivan SubbarayanSubbarayan on a 1989 stamp of IndiaGovernor of MaharashtraIn office17 April 1962 – 6 October 1962Prime MinisterJawaharlal NehruPreceded bySri PrakasaSucceeded byVijayalakshmi PanditUnion Minister for Transport and CommunicationIn office1959–1962PresidentRajendra PrasadPrime MinisterJawaharlal NehruMember of Parliament (Lok Sabha) for TiruchengodeIn office1957–1962PresidentRajendra PrasadPrime MinisterJawaharlal NehruPreceded byS. Kandaswa…

British VTOL jet fighter aircraft Sea Harrier A Sea Harrier FA2 of 801 NAS in flight at the Royal International Air Tattoo. Role V/STOL strike fighterType of aircraft National origin United Kingdom Manufacturer Hawker Siddeley British Aerospace Introduction 20 August 1978 (FRS1) 10 December 1983 (FRS51)2 April 1993 (FA2) Retired March 2006 (Royal Navy); 6 March 2016 (Indian Navy)[1] Status Retired Primary users Royal Navy (historical)Indian Navy (historical) Number built 98 Develope…

Location of the state of Texas in the United States of America The following is a list of symbols of the U.S. state of Texas. Official designations and symbols Type Symbol Date designated Image Motto Friendship 1930 [1] Nickname The Lone Star State[2] Flag The Lone Star Flag June 30, 1839 National seal Seal of the Republic of Texas January 25, 1839 State seal Seal of Texas December 29, 1845 Reverse of the seal August 26, 1961 National coat of arms Coat of arms of the Republic of …

American politician from Michigan Lana TheisMember of the Michigan Senatefrom the 22nd districtIncumbentAssumed office January 1, 2019Preceded byJoe HuneMember of the Michigan House of Representativesfrom the 42nd districtIn officeJanuary 1, 2015 – December 31, 2018Preceded byBill RogersSucceeded byAnn Bollin Personal detailsBorn (1965-06-23) June 23, 1965 (age 58)Sturgis, Michigan, U.S.Political partyRepublicanEducationCalifornia State University, Fullerton (BS) …

Kembali kehalaman sebelumnya