Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. section .text
  2. global _start ;must be declared for using gcc
  3.  
  4. _start: ;tell linker entry point
  5. ;create the file
  6. mov eax, 8
  7. mov ebx, file_name
  8. mov ecx, 0777 ;read, write and execute by all
  9. int 0x80 ;call kernel
  10.  
  11. mov [fd_out], eax
  12.  
  13. ; write into the file
  14. mov edx,len ;number of bytes
  15. mov ecx, msg ;message to write
  16. mov ebx, [fd_out] ;file descriptor
  17. mov eax,4 ;system call number (sys_write)
  18. int 0x80 ;call kernel
  19.  
  20. ; close the file
  21. mov eax, 6
  22. mov ebx, [fd_out]
  23.  
  24. ; write the message indicating end of file write
  25. mov eax, 4
  26. mov ebx, 1
  27. mov ecx, msg_done
  28. mov edx, len_done
  29. int 0x80
  30.  
  31. ;open the file for reading
  32. mov eax, 5
  33. mov ebx, file_name
  34. mov ecx, 0 ;for read only access
  35. mov edx, 0777 ;read, write and execute by all
  36. int 0x80
  37.  
  38. mov [fd_in], eax
  39.  
  40. ;read from file
  41. mov eax, 3
  42. mov ebx, [fd_in]
  43. mov ecx, info
  44. mov edx, 26
  45. int 0x80
  46.  
  47. ; close the file
  48. mov eax, 6
  49. mov ebx, [fd_in]
  50. int 0x80
  51.  
  52. ; print the info
  53. mov eax, 4
  54. mov ebx, 1
  55. mov ecx, info
  56. mov edx, 26
  57. int 0x80
  58.  
  59. mov eax,1 ;system call number (sys_exit)
  60. int 0x80 ;call kernel
  61.  
  62. section .data
  63. file_name db 'myfile.txt'
  64. msg db 'Welcome to Tutorials Point'
  65. len equ $-msg
  66.  
  67. msg_done db 'Written to file', 0xa
  68. len_done equ $-msg_done
  69.  
  70. section .bss
  71. fd_out resb 1
  72. fd_in resb 1
  73. info resb 26
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement