i want to call lseek and llseek syscall (without using glibc wrapper, i'm doing this for learning purpose) from asm. i wrote the code below to do just that, but when i run it, it shows segmentation fault which i understand is happening because i'm trying access a memory out of the block allocated to us. Any way i can solve it?
section .text
global _start ;must be declared for using gcc
_start:
;open the file for reading
mov eax, 5
mov ebx, file_name
mov ecx, 2 ;for RDWD access
mov edx, 0777 ;read, write and execute by all
int 0x80
mov [fd_out], eax
; write into the file
mov edx,len ;number of bytes
mov ecx, msg ;message to write
mov ebx, [fd_out] ;file descriptor
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
;change offset
mov eax, 19
mov ebx, [fd_out]
mov ecx, 7 ;for read only access
mov edx, 0 ;SEEK_SET
int 0x80
; write into the file
mov edx,lntwo ;number of bytes
mov ecx, mgafter ;message to write
mov ebx, [fd_out] ;file descriptor
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
section .data
file_name db 'myfile.txt'
msg db 'Welcome to jj'
mgafter db ' Shashwat'
lntwo equ $-mgafter
len equ $-msg
section .bss
fd_out resb 1
fd_in resb 1
info resb 26