【发布时间】:2013-02-25 21:58:41
【问题描述】:
以下是我希望是来自我的 NASM 程序的相关代码。一旦调用了 int 080h,调试器就会显示 eax 的 -9。我的 test.txt 中的文本是 321314145。我已经盯着这个看了好几个小时了,我在这里遇到了死胡同。为什么会这样?
%define BUFLEN 128
%define READLEN 3
%define SYSCALL_READ 3
SECTION .bss ; uninitialized data section
buf: resb READLEN ; buffer for read
rlen: resb 4
newstr: resb BUFLEN
; read file name from arg
;
pop ebx ;not using
pop ebx ;not using
pop ebx ;pop filename
; open file
;
mov eax, SYSCALL_OPEN
mov ecx, STDIN
int 080h
mov eax, SYSCALL_READ ; read function
mov ebx, eax ; Arg: file descriptor
mov ecx, buf ; Arg: address of buffer
mov edx, READLEN ; Arg: buffer length
int 080h
【问题讨论】:
-
你怎么好像在打开
stdin,而你的文本却在一个文件中? -
我只是使用常量,它指向0,是只读模式
-
使用
strace ./a.out来跟踪您的系统调用并查看您将垃圾作为参数传递给open(2),因此您当然会得到-ERRNO 返回值而不是fd。
标签: file assembly file-io x86 nasm