initial checkin from subversion
This commit is contained in:
43
file1/file1.lst
Normal file
43
file1/file1.lst
Normal file
@@ -0,0 +1,43 @@
|
||||
1 section .data
|
||||
2 00000000 48656C6C6F2C20776F- hello db 'Hello, world!',10 ; Our dear string
|
||||
3 00000009 726C64210A
|
||||
4 helloLen equ $ - hello ; Length of our dear string
|
||||
5
|
||||
6 section .text
|
||||
7 global _start
|
||||
8
|
||||
9 _start:
|
||||
10 00000000 5B pop ebx ; argc (argument count)
|
||||
11 00000001 5B pop ebx ; argv[0] (argument 0, the program name)
|
||||
12 00000002 5B pop ebx ; The first real arg, a filename
|
||||
13
|
||||
14 00000003 B808000000 mov eax,8 ; The syscall number for creat() (we already have the filename in ebx)
|
||||
15 00000008 B9A4010000 mov ecx,00644Q ; Read/write permissions in octal (rw_rw_rw_)
|
||||
16 0000000D CD80 int 80h ; Call the kernel
|
||||
17 ; Now we have a file descriptor in eax
|
||||
18
|
||||
19 0000000F 85C0 test eax,eax ; Lets make sure the file descriptor is valid
|
||||
20 00000011 7805 js skipWrite ; If the file descriptor has the sign flag
|
||||
21 ; (which means it's less than 0) there was an oops,
|
||||
22 ; so skip the writing. Otherwise call the filewrite "procedure"
|
||||
23 00000013 E809000000 call fileWrite
|
||||
24
|
||||
25 skipWrite:
|
||||
26 00000018 89C3 mov ebx,eax ; If there was an error, save the errno in ebx
|
||||
27 0000001A B801000000 mov eax,1 ; Put the exit syscall number in eax
|
||||
28 0000001F CD80 int 80h ; Bail out
|
||||
29
|
||||
30 ; proc fileWrite - write a string to a file
|
||||
31 fileWrite:
|
||||
32 00000021 89C3 mov ebx,eax ; sys_creat returned file descriptor into eax, now move into ebx
|
||||
33 00000023 B804000000 mov eax,4 ; sys_write
|
||||
34 ; ebx is already set up
|
||||
35 00000028 B9[00000000] mov ecx,hello ; We are putting the ADDRESS of hello in ecx
|
||||
36 0000002D BA0E000000 mov edx,helloLen ; This is the VALUE of helloLen because it's a constant (defined with equ)
|
||||
37 00000032 CD80 int 80h
|
||||
38
|
||||
39 00000034 B806000000 mov eax,6 ; sys_close (ebx already contains file descriptor)
|
||||
40 00000039 CD80 int 80h
|
||||
41 0000003B C3 ret
|
||||
42 ; endp fileWrite
|
||||
43
|
||||
Reference in New Issue
Block a user