카테고리

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/05

일반적인 Nasm 파일 구성

Section .data
; 주석 표현

hello: db 'this is an example string', 10
HelloLenghth: equ 26

;db = 바이트 정의, dw = word 정의, dd = word 정의

Section .bss
;여기는 수정 가능한 변수를 선언
Variable1: resb 255
Variable2: resb 1
Variable3: resw 1

Section .text
;프로그램 코드로 이동

global _start ; 외부 프로그램 시작
_start:              ;프로그램이 실제로 시작
                          ;여기에서 코딩 시작

Example File
Section .data
hello:    db 'Hello world!',10
helloLen: equ 13

section .text
global _start
_start:
    mov eax, 4       ;리눅스 sys_write 호출
    mov ebx, 1       ;파일 기술자
                     
    mov ecx, hello   ;문자열 주소 넣기 
                     
    mov edx,helloLen ;hello 문자열 공간 크기 
    
    int 80h          ;리눅스 시스템 인터럽트 
                         
    mov eax, 1    ; sys_exit 호출
                     
    mov ebx,0    ;매개변수 0
    int 80h          ;리눅스 시스템 인터럽트 

Compile: 
nasm -f elf filename.asm
ld -s -o outputfilename filename.o


댓글 없음:

댓글 쓰기