section .data
line db "This is Francois on First Line.", 0xa, 0
len equ $ - line
line2 db "This is Francois on second Line.", 0xa, 0
len2 equ $ - line2
section .bss
bssbuf: resb len
file: resb 8
section .text
global _start
_start:
nop ; for gdb debugger
pop ebx ; argc
cmp ebx,2 jne error ; less or more args
pop ebx ; name of the program (argv[0])
pop ebx ; next arg is name of file cmp ebx,0 ; check if ebx is not zero (ok)
jbe error ; to exit
mov [file], ebx ; store filename in local variable
; file creation mov eax,8
mov ecx,511 ; access rigths
int 80h
cmp eax,0 ; created ok =0
jbe error
; open file in read-write
mov eax,5
mov ebx, [file] ;name of file for sys_open
mov ecx,1 ; 0_RDWR
int 80h
cmp eax,0 ; check if opened ?
jbe error
mov ebx,eax ; store file descriptor of the new file
; write line1 to the file pointer (ebx)
mov eax,4 ; sys_write
mov ebx,[file]
mov edx,len
mov ecx,line
int 80h
; writhe second line to the file
mov eax,4
mov edx,len2
mov ecx,line2
int 80h
; sync all writ buffers with files
mov eax,36 ; sys_sync
int 80h
; close file (file descriptor in ebx is no longer valid
mov eax,6
int 80h
mov eax,1
mov ebx,0
int 80h ; exit 0
error:
mov ebx,eax ; get exit_code
mov eax,1 ; exit(exit_code)
int 80h |