10 참고자료

1. NASM에서 Macro 사용법

NASM에서 Macro의 작성법은 아래와 같다.

Macros
The built-in macro system has the following syntax:

.macro <name> <args>
<operations>
.endm

Example:

 

.macro write string  
movw string, %si  
call printstr.
endm


This would be equivalent to the NASM macro:

  1. %macro write 1  
    mov si, %1  
    call printstr
    %endmacro

 

상당히 유용한 기능인것 같다. 코드가 확 줄어버리네. @0@

 

2. NASM에서 C에서 호출 가능한 함수 작성법

크게 세부분으로 나눌 수 있다.

 

각 부분을 정의하는 코드는 아래와 같다.

  1. [bits 32]     <= bit 설정 부분
  2.  
  3. global _kInit <= 외부로 export할 함수 또는 변수명
  4.  
  5. extern _main  <= 어셈블리어 파일에서 C 함수 또는 다른 함수를 호출할때 외부에 있다는 것을 알림
  6.  
  7. section .text <= 섹션 정의부, 코드 영역임을 알림
  8.  
  9. _kInit:       <= 함수부
       mov      ax, 0x10
       mov      ds, ax
  10.    call     main
  11.    retn 

위와 같이 쓰면 사용할 수 있다.