카테고리

asm (27) bootloader_x86_grub (1) C (92) compile (11) config (76) CPP (13) CSS (1) debugging (7) gimp (1) Go (1) html (1) Java (1) JavaScript (1) kernel (19) LibreOffice (3) Linux system progamming (21) MFC (1) opencv (4) OpenGL (1) PHP (1) Python (4) qemu (29) shell (3) socket (7) troubleshooting (2) ubuntu18.04 (2) windows (1)

2018/12/07

asm NASM 64 구조


NASM 구조


section .text
_start: mov rax, 1 ;쓰기 시스템 호출
  mov rdi, 1 ;stdout=1 모니터 출력
  mov rsi, message ;출력 할 문자열 주소
  mov rdx, 13 ;몇 바이트 사용 수
  syscall ;운영체제 쓰기 호출
  mov rax, 60 ;종료를 위한 시스템 호출
  xor rdi, rdi ;종료 코드 0
 syscall ;종료(운영체제 자원 회수)

section .data
message: db "hello, Wrold", 10 ;숫자 10 개행 문자 \n



레이블 명령 피연산자
지시어

global start
분류 Start: Sction .text
mov Rax, 1
mov Rdi, 1
mov Rsi, message
mov Rdx, 13
syscall

mov Rax, 60
xor Rdi, rdi








Message:
Section .data
Db Hello, World”, 10






section .data
text db "Hello, World!",10

section .text
global _start


_start:
mov rax, 1
mov rdi, 1
mov rsi, text
mov rdx 14
syscall

mov rax, 60
mov rdi, 0
syscall

;compile
;nasm -f elf64 -o hello.o hello.asm
;ld hello.o -o hello

지시어 정리
db: 코드에 삽입 할 데이터의 원시 바이트를 정의한다.
"Hello, World!",10: 정의하는 데이터의 바이트, 텍스트 문자열의 각 문자는 단일 바이트이고, "10"은 "\n" 개행 문자를 타나낸다.

text
데이터가있는 메모리의 주소에 할당 된 이름이다.
나중에 코드에서 "text"를 사용할 때마다 코드가 컴파일 될 때 컴파일러는이 데이터에서 메모리의 실제 위치를 확인하고 "text"의 모든 인스턴스를 해당 메모리 주소로 바꾼다.

text db "hello, world!",10
text: 메모리 주소의 이름
db: 바이트 정의
"hello, World!",10: 정의 된 바이트

댓글 없음:

댓글 쓰기