Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #Leopold von Niebelschuetz-Godlewski
  2. #Homework for "Programming from the Ground Up - Chapter 5"
  3. #Purpose: Creates a file that's called "heynow.txt" with the string "Hey diddle diddle!\n".
  4. .section .data
  5.  
  6. #system call numbers
  7. .equ SYS_OPEN, 5
  8. .equ SYS_WRITE, 4
  9. .equ SYS_CLOSE, 6
  10. .equ SYS_EXIT, 1
  11.  
  12. #options for SYS_OPEN call
  13. .equ O_RDONLY, 0
  14. .equ O_CREAT_WRONLY_TRUNC, 03101
  15. .equ PERMISSIONS, 0666
  16.  
  17. #strings to be used
  18. diddle_string:
  19. .ascii "Hey diddle diddle!\n\0"
  20.  
  21. file_name:
  22. .ascii "heynow.txt\0"
  23.  
  24. .section .text
  25. .globl _start
  26.  
  27. #okay, game time >.<
  28.  
  29. _start:
  30. #no code required here... hi =)....
  31.  
  32. get_fd_write:
  33. movl $SYS_OPEN, %eax
  34. movl $file_name, %ebx
  35. movl $O_CREAT_WRONLY_TRUNC, %ecx
  36. movl $PERMISSIONS, %edx
  37. int $0x80 #fd now stored in %eax
  38. pushl %eax
  39.  
  40. write_file:
  41. movl $20, %edx #size of our string
  42. movl %eax, %ebx # %eax contains the fd
  43. movl $SYS_WRITE, %eax
  44. movl $diddle_string, %ecx
  45. int $0x80
  46.  
  47. close_files:
  48. movl $SYS_CLOSE, %eax
  49. popl %ebx
  50. int $0x80
  51.  
  52. exit:
  53. movl $SYS_EXIT, %eax
  54. movl $0, %ebx
  55. int $0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement