Advertisement
Guest User

Untitled

a guest
Aug 10th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. calls.asm==========================
  2. global sys_read
  3. global sys_write
  4. global sys_errno
  5.  
  6. section .text
  7.  
  8. generic_syscall_3:
  9. push ebp
  10. mov ebp, esp
  11. push ebx
  12. mov ebx, [ebp+8]
  13. mov ecx, [ebp+12]
  14. mov edx, [ebp+16]
  15. int 80h
  16. mov edx, eax
  17. and edx, 0fffff000h
  18. cmp edx, 0fffff000h
  19. jnz .okay
  20. mov [sys_errno], eax
  21. xor eax, eax
  22. not eax
  23. .okay:
  24. pop ebx
  25. mov esp, ebp
  26. pop ebp
  27. ret
  28.  
  29. sys_read: mov eax, 3
  30. jmp generic_syscall_3
  31. sys_write: mov eax, 4
  32. jmp generic_syscall_3
  33.  
  34. section .bss
  35. sys_errno resd 1
  36.  
  37. start.asm==========================
  38. global _start
  39. extern main
  40.  
  41. section .text
  42. _start: mov ecx, [esp] ; argc in ecx
  43. mov eax, esp
  44. add eax, 4 ; argv in eax
  45. push eax
  46. push ecx
  47. call main
  48. add esp, 8 ; clean the stack
  49. mov ebx, eax ; now call _exit
  50. mov eax, 1
  51. int 80h
  52.  
  53. hello.c==========================
  54. int sys_write(int fd, const void *buf, int size);
  55.  
  56. int main(int argc, char **argv)
  57. {
  58. sys_write(1, "Hello, world\n", 13);
  59. return 0;
  60. }
  61.  
  62. Сборка==========
  63. nasm -f elf start.asm
  64. nasm -f elf calls.asm
  65. gcc -Wall -nostdlib -Os -s -m32 -c hello.c
  66. ld -strip-all start.o calls.o hello.o -o hello
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement