Ladies_Man

#ccc how-to assemble and link

Jan 25th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   GNU nano 2.2.6              Файл: hello32.s                                  
  2.  
  3. .text
  4.  
  5. .global _start
  6. _start:
  7.         push    %esp
  8.         push    $print_fmt
  9.         call   printf
  10.  
  11.         movl    $0, (%esp)   # reuse the stack slots we set up for printf, inst$
  12.         call    exit         # exit(3) does an fflush and other cleanup
  13.  
  14. .section .rodata
  15. print_fmt: .asciz "Hello, World!\n%%esp at startup = %#lx\n"
  16.  
  17.  
  18. anthony:~/Dropbox/bero$ gcc -m32 -nostartfiles hello32.s
  19. anthony:~/Dropbox/bero$ ./a.out
  20. Hello, World!
  21. %esp at startup = 0xffd65ab0
  22.  
  23.  
  24.  
  25.  
  26.  
  27.    .data
  28. format: .asciz "hallo %d\n"
  29. .text
  30.     .global main
  31. main:
  32.   mov  $format, %rdi
  33. #  mov  $1, %rsi           # Writing to ESI zero extends to RSI.
  34. #  xor %eax, %eax          # Writing to EAX zero extends to RAX.
  35.   call puts
  36.   ret
  37.  
  38.  
  39. anthony:~/Dropbox/bero$ nano hello32.s
  40. anthony:~/Dropbox/bero$ gcc hello32.s
  41. anthony:~/Dropbox/bero$ ./a.out
  42. hallo %d
  43.  
  44. anthony:~/Dropbox/bero$ nano hello32.s
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. anthony:~/Dropbox/bero$ as -o hello32.o hello32.s
  53. anthonyd:~/Dropbox/bero$ ld -o hell -dynamic-linker /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o -lc hello32.o /usr/lib/x86_64-linux-gnu/crtn.o
  54. anthony:~/Dropbox/bero$ ./hell
  55. hallo %d
  56.  
  57. anthony:~/Dropbox/bero$
Add Comment
Please, Sign In to add comment