어셈블리어로 Hello World 출력
터미널을 키고 nano helloworld.s 를 쳐준다
nano는 에디터이다
.s는 어셈블러 소스코드라는걸 알려주는 확장자
setction .data (이때 data는 흔히 문자열 같은 데이터를 보관하는 공간)
msg db "Hello World"
section .text (section은 위에서부터 차례대로 읽어오는 코드)
global_start
_start: (함수이름 정의)
mov rax, 1 (mov는 어떠한 레지스터 안에 특정한 값을 집어넣는 명령어 rax에 1을 넣겠다는 뜻)
mov rdi, 1
mov rsi, msg
mov rdx, 12
syscall
mov rax, 60
mov rdi, 0
syscall
이렇게 작성한 소스코드는 cat 명령어를 통해 확인할 수 있다
cat helloworld.s
이제 작성한 어셈블리어 코드를 실제 파일로 변경하려면
nasm -f elf64 -o helloworld.o helloworld.s
ld -o helloworld helloworld.o
ls 하면 helloworld 라고 실행할 수 있는 파일이 생겨난 것을 볼 수 있다
./helloworld 하면 Hello World 라고 정상적으로 출력이 된다