1 / 4

시스템 프로그래밍 실습

시스템 프로그래밍 실습. ASSEMBLY 1. C 코드와 ASSEMBLY 코드의 상호 참조. EXAMPLE 1. ( c_source.c ) #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { int num, exp, res; num = atoi(argv[1]); exp = atoi(argv[2]); num = myfunc(num, exp);

avak
Download Presentation

시스템 프로그래밍 실습

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 시스템 프로그래밍 실습 ASSEMBLY 1

  2. C 코드와 ASSEMBLY 코드의 상호 참조 EXAMPLE 1 ( c_source.c ) #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { int num, exp, res; num = atoi(argv[1]); exp = atoi(argv[2]); num = myfunc(num, exp); printf(“%d exp %d = %d\n”, num, exp, res); return 0; } int print(int num, int exp, int res) { printf(“%d exp %d = %d\n”, num, exp, res); return 0; }

  3. EXAMPLE 1 ( asm_source.s ) .globl myfunc myfunc: movl 4(%esp), %eax movl 8(%esp), %ebx movl $1, %ecx movl $1, %edx L1: cmpl %edx, %ebx je L2 imull %eax, %ecx pushl %ecx pushl %edx pushl %eax call print popl %eax popl %edx popl %ecx incl %edx jmp L1 L2: imull %eax, %ecx movl %ecx, %eax ret 컴파일 방법 gcc –o ex1 c_sources.c asm_source.s

  4. INLINE ASSEMBLY EXAMPLE 2 ( c_source.c ) int iasm_test_func(int arg); void print(char* str, int num) { printf(“STRING : %s NUMBER : %d\n”, str, num); } static void __iasm_func_dummy(void) { __asm__ __volatile__( “.globl iasm_test_func \n\t” “iasm_test_func: \n\t” “pushl 4(%%esp) \n\t” “pushl %0 \n\t” “call print \n\t” “addl $8, %%esp \n\t” “movl 4(%%esp), %%eax \n\t” “ret “ : : “I” (“hello world..”) ); } int main() { int ret; ret = iasm_test_func(10); printf(“RETURN = %d\n”, ret); return 0; }

More Related