本文介绍了Linux中的文件操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好: 我正在编写一个小程序集程序,它将打开一个文件,处理它b $ b,然后再关闭它。我正在努力构建一个简单的框架。为了它 目前。我已经打开,关闭和退出系统调用了, 但我觉得有问题。 我的代码是下面。它似乎工作正常,它只是静默运行,如下面给出 。但是如果我尝试使用不存在的文件(例如将/ dev / zero更改为 / dev / zer),则不会产生错误消息。 感谢您的任何建议! section .text path db" / dev / zero",0x00 global _start _start: mov eax,5;打开 mov ebx,路径 xor ecx,ecx; O_RDONLY mov edx,0x100; S_IRUSR int 0x80 xchg eax,ebx;将fd放入ebx mov eax,6;关闭 int 0x80 mov eax,1;退出 int 0x80 Hello all: I''m writing a small assembly program that will open a file, processit, then close it again. I''m trying to build a simple "framework" for itat the moment. I''ve got the open, close, and exit system calls in place,but I think there''s something wrong. My code is below. It seems to work OK, it just runs silently as givenbelow. But if I try it with a non-existent file (e.g. change /dev/zero to/dev/zer) then no error message is produced. Thanks for any advice!section .text path db "/dev/zero",0x00 global _start_start:mov eax,5 ; openmov ebx,pathxor ecx,ecx ; O_RDONLYmov edx,0x100 ; S_IRUSRint 0x80 xchg eax,ebx ; put fd into ebxmov eax,6 ; closeint 0x80 mov eax,1 ; exitint 0x80 推荐答案 这并不奇怪 - 你没有告诉它产生错误 消息!如果你使用一个不存在的文件,那么open()系统调用 *会*通过 返回一个负面的nunber,通知你的程序有问题在eax。你只需选择忽略这个... 其他几件事:因为你没有创建文件,所以打开模式 参数()被忽略,所以预先在edx中放置任何特殊的东西是没有意义的。 你无需使用xchg指令,无论如何你立即使用了。而且你最后没有给shell返回一个明智的退出 状态。 这里是你修改这些东西的代码: 节.data path db" / dev / zero",0x00 errmsg db"打开文件时出错! ,0x0A errlen equ That''s hardly surprising - you didn''t tell it to produce an errormessage! If you use a non-existent file, then the open() system call*will* thoughtfully inform your program that there was a problem, byreturning a negative nunber in eax. You just choose to ignore this... A couple of other things: as you''re not creating a file, the modeargument to open() is ignored, so there''s no point putting anythingspecial in edx beforehand. There''s no need for the xchg instruction whenyou immediately clobber eax anyway. And you don''t return a sensible exitstatus to the shell at the end. Here''s your code with these things fixed up:section .data path db "/dev/zero",0x00errmsg db "Error opening file!",0x0Aerrlen equ 这是无可争议的偏离主题。请不要在这里回复 来保护新闻组。 - 免费游戏和编程好东西。 http://www.personal.leeds.ac.uk/~bgy1mm 这篇关于Linux中的文件操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 03:36