Advertisement
Guest User

Untitled

a guest
Oct 26th, 2012
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #############################################3
  2. #% as -o argc.o argc.s && ld -o argc argc.o
  3. #% ./argc 3 4 5
  4. #4
  5. #
  6. #% as -o argc.o argc.s && ld -o argc argc.o -lc
  7. #% ./argc 4 5 6
  8. #zsh: no such file or directory: ./argc
  9. #
  10. #% gcc -m64 -o argc argc.s -nostdlib
  11. #% ./argc 3 4 5
  12. #4
  13. #
  14. #% gcc -m64 -o argc argc.s
  15. #/tmp/ccfN2MUC.o: In function `_start':
  16. #(.text+0x0): multiple definition of `_start'
  17. #/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../../lib64/crt1.o:(.text+0x0): first defined here
  18. #/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../../lib64/crt1.o: In function `_start':
  19. #(.text+0x20): undefined reference to `main'
  20. #collect2: ld returned 1 exit status
  21. #
  22. ### Меняем `_start:' на `main:'
  23. #
  24. #% gcc -m64 -o argc argc.s
  25. #% ./argc 3 4 5
  26. #=���
  27. #
  28. ### Код:
  29.  
  30.  .globl _start
  31.  
  32.   .data
  33. newline: .ascii "\n"
  34.  .set newline_len, . - newline
  35.  
  36.  .bss
  37. argc: .space 8
  38.  
  39.  .text
  40. _start:
  41.  movq $1, %rax
  42.  movq $1, %rdi
  43.  movq (%rsp), %rbx
  44.  movq %rbx, argc
  45.  addq $48, argc
  46.  movq $argc, %rsi
  47.  movq $8, %rdx
  48.  syscall
  49.  
  50.  movq $1, %rax
  51.  movq $1, %rdi
  52.  movq $newline, %rsi
  53.  movq $newline_len, %rdx
  54.  syscall
  55.  
  56.  movq $60, %rax
  57.  xorq %rdi, %rdi
  58.  syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement