Assembly 程序集x86 ia-32中的缓冲区和文件大小
我在Linux x86(IA-32)上玩汇编,在Assembly 程序集x86 ia-32中的缓冲区和文件大小,assembly,system-calls,x86,Assembly,System Calls,X86,我在Linux x86(IA-32)上玩汇编,在readsyscall过程中遇到了一些问题 global _start section .text _start: mov eax,5 ;open mov ebx,filename ;path to file mov ecx,0000o ;O_RDONLY int 0x80 mov ebx,eax ;fd in ebx mov eax,3 ;read
read
syscall过程中遇到了一些问题
global _start
section .text
_start:
mov eax,5 ;open
mov ebx,filename ;path to file
mov ecx,0000o ;O_RDONLY
int 0x80
mov ebx,eax ;fd in ebx
mov eax,3 ;read
;buffer?
;count?;
int 0x80
mov eax,0x1 ;exit
mov ebx,0x5 ;ret code
int 0x80
section .data
filename: db "path-to-file"
我有两个问题,因为:
您可以使用
sys\u fstat
获取文件大小,例如sys\u brk
为缓冲区分配内存。有关系统调用的列表,请参阅。嗯,好的,谢谢!另一个疑问是:如何将参数struct\uu old\u kernel\u stat*
传递给ecx reg?它是一个指针,即指向足够容纳struct stat
的内存块的地址。好的!所以在x86中,sizeof(struct stat)是88个字节,所以我需要88个字节到.bss部分,对吗?然后要访问文件大小,我需要执行一个lea edx,[var in bss section]+32
,因为long st_size
是结构中的第9个元素,有8个元素,每个元素有4个字节。我说的对吗?您可以在nasm中声明结构(参见示例)