Netwide Assembler
lastmod 2019-04-04created 2014-02-1110 edits
The Netwide Assembler (NASM) is an assembler and disassembler for the Intel x86 architecture. It can be used to write 16-bit, 32-bit (IA-32), and 64-bit (x86-64) programs. NASM is considered one of the most popular assemblers for Linux.
NASM was originally written by Simon Tatham with assistance from Julian Hall. As of 2016, it is maintained by a small team led by H. Peter Anvin. It is open-source software released under the terms of the simplified (2-clause) BSD license.
How to install in Ubuntu
Hello, world
section .data ;섹션 .data 를 선언한다.(여기부터
; .data 섹션이다.)
msg db "Hello, world!",0xa ;출력할 사랑스런(!) 스트링이다.
len equ $ - msg ;친애하는(!) 문자열의 길이
section .text ;여기부터 .text 섹션이다. 코드있음
;ELF 링커나 로더에게 프로그램의 엔트리 포인트를 알려주어야
global _start ;한다. 로더 혹은 링커는 일반적으로 엔트리 포인트가 _start
;라고 가정하고 있다. 이 디폴트 설정을 바꿀려면,
;ld -e foo 를 사용하라.
_start:
;stdout 에 우리의 사랑스런 문자열을 출력하자.
mov edx,len ;시스템 콜 4번(sys_write)은 세번째 인수로 출력할 메세지의
;길이를 취한다.
mov ecx,msg ;시스템 콜 4번은 두번째 인수로 출력할 메세지가 담긴 메모리
;주소를 취한다. 즉, 출력할 메세지로의 포인터를 취한다.
mov ebx,1 ;시스템 콜 4번은 첫번째 인수로 파일의 핸들(디스크립터)을
;취한다.
mov eax,4 ;eax 레지스터에 호출할 커널 시스템 콜의 번호를 넣어 준다.
;이 경우에는 4번(sys_write) 이다.
int 0x80 ;커널을 호출한다.
;출력이 끝났으면, exit 를 호출한다.
mov ebx,0 ;exit 코드로 0을 준다. (c 코드로는 exit(0);)
mov eax,1 ;시스템 콜 1번 (sys_exit)
int 0x80 ;커널을 호출한다.
See also
Favorite site
- NASM website
- Wikipedia (en) description of NASM
- Making a bootloader - 1
- Assembly, a language still in use today
- [Recommended] Programming from the Ground Up (ko)