Skip to content

맥에서 nasm 으로 어셈블리어를 작성해보자

License

Notifications You must be signed in to change notification settings

KKodiac/assembly-macosx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

assembly-macosx

심심할 때 인텔 기반 맥에서 어셈블리어를 작성해보자

How to execute the Assembler

>$ nasm -f macho64 <.asm 파일>

>$ ld -macosx_version_min 10.7.0 -o <execution 파일명> <object 파일명>

>$ ./<execution 파일명>

레지스터(64비트)

아래는 많이 사용한다는 레지스터의 의미이다.

Register Conventional use Low 32-bits Low 16-bits Low 8-bits
%rax Return value, callee-owned %eax %ax
%rdi 1st argument, callee-owned %edi %di
%rsi 2nd argument, callee-owned %esi %si
%rdx 3rd argument, callee-owned %edx %dx
%rcx 4th argument, callee-owned %ecx %cx
%r8 5th argument, callee-owned %r8d %r8w
%r9 6th argument, callee-owned %r9d %r9w
%r10 Scratch/temporary, callee-owned %r10d %r10w
%r11 Scratch/temporary, callee-owned %r11d %r11w
%rsp Stack pointer, caller-owned %esp %sp
%rbx Local variable, caller-owned %ebx %bx
%rbp Local variable, caller-owned %ebp %bp
%r12 Local variable, caller-owned %r12d %r12w
%r13 Local variable, caller-owned %r13d %r13w
%r14 Local variable, caller-owned %r14d %r14w
%r15 Local variable, caller-owned %r15d %r15w
%rip Instruction pointer
%eflags Status/condition code bits

MacOS vs Linux

Syscall

첫번째 맥에서와 리눅스 기반 시스템에서 nasm syntax의 차이는 system call에서 있다. 예를 들어

# Write 작업에 대한 system call은
맥: 0x02000004
리눅스: 1

# Exit 작업에 대한 system call은
맥: 0x02000001
리눅스: 60

이렇게 다르다

참고자료

About

맥에서 nasm 으로 어셈블리어를 작성해보자

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published