我想从asm调用lseek和llseek系统调用(不使用glibc包装器,我这样做是为了学习目的)。我写下面的代码来做到这一点,但是当我运行它时,它显示了我理解正在发生的分段错误,因为我试图从分配给我们的块中访问内存。我能以任何方式解决它吗?
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