-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtowrite.s
More file actions
45 lines (33 loc) · 1.23 KB
/
towrite.s
File metadata and controls
45 lines (33 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# PURPOSE: This program creates new file
#
.section .data
SYS_WRITE:
.ascii "w"
filename:
.ascii "heynow.txt\0"
text:
.ascii "Hey diddle diddle!\n\0"
.section .bss
.lcomm FILE_STRUCT, 1
.section .text
.globl _start
_start:
movl %esp, %ebp
subl $4, %esp # allocate space for file struct
# create/open file
pushl $SYS_WRITE # write mode
pushl $filename # filename into
call fopen # call fopen
addl $8, %esp
# save file struct
movl %eax, -4(%ebp) # save file struct
# write text to file
pushl -4(%ebp) # file struct
pushl $text # text
call fputs # call fputs
# close file
pushl -4(%ebp) # file struct
call fclose # call fclose
# exit program
pushl $0
call exit