openfile.asm
sys_read equ 3
sys_write equ 4
sys_open equ 5
sys_close equ 6
o_rdonly equ 0
format ELF executable
segment readable executable
start:
;int fid = open("file.txt",O_RDONLY);
mov eax, sys_open
mov ebx, f
mov ecx, o_rdonly
int 80h
mov dword [f_id], eax
;read( fid , &buf[0] , 12 );
mov ebx, eax
mov eax, sys_read
mov ecx, f_buf
mov edx, f_buf_len
int 80h
;write( 1 , &buf[0] , 12 );
mov eax, sys_write
mov ebx, 1
mov ecx, f_buf
mov edx, f_buf_len
int 80h
;close( fid );
mov eax, sys_close
mov ebx, dword [f_id]
int 80h
mov eax , 1
xor ebx, ebx
int 80h ;system interupt
segment readable writeable
f db "file.txt",0
f_len = $-f
f_buf db 12 dup 0
f_buf_len = $-f_buf
f_id dd 0
fasm openfile.asm openfile
C programm
of.c
#include <fcntl.h>
int main()
{
int fid = open("file.txt",O_RDONLY);
char buf[12];
read( fid , &buf[0] , 12 );
write( 1 , &buf[0] , 12 );
close( fid );
return 0;
}gcc of.c -o of