Directory Listing Program

Let’s write a short program that clears the screen, displays the current disk directory, and asks
the user to enter a filename. (You might want to extend this program so it opens and displays the
selected file.)
C++ Stub Module The C++ module contains only a call to asm_main, so we can call it a
stub module:

// main.cpp
// stub module: launches assembly language program
extern "C" void asm_main(); // asm startup proc
void main()
{
asm_main();
}

ASM Module The assembly language module contains the function prototypes, several strings,
and a fileName variable. It calls the system function twice, passing it “cls” and “dir” commands.

Then printf is called, displaying a prompt for a filename, and scanf is called so the user can input
the name. It does not make any calls to the Irvine32 library, so we can set the .MODEL directive to
the C language convention:

; ASM program launched from C++ (asmMain.asm)
.586
.MODEL flat,C
; Standard C library functions:
system PROTO, pCommand:PTR BYTE
printf PROTO, pString:PTR BYTE, args:VARARG
scanf PROTO, pFormat:PTR BYTE,pBuffer:PTR BYTE, args:VARARG
fopen PROTO, mode:PTR BYTE, filename:PTR BYTE
fclose PROTO, pFile:DWORD
BUFFER_SIZE = 5000
.data
str1 BYTE "cls",0
str2 BYTE "dir/w",0
str3 BYTE "Enter the name of a file:",0
str4 BYTE "%s",0
str5 BYTE "cannot open file",0dh,0ah,0
str6 BYTE "The file has been opened",0dh,0ah,0
modeStr BYTE "r",0
fileName BYTE 60 DUP(0)
pBuf DWORD ?
pFile DWORD ?
.code
asm_main PROC
; clear the screen, display disk directory
INVOKE system,ADDR str1
INVOKE system,ADDR str2
; ask for a filename
INVOKE printf,ADDR str3
INVOKE scanf, ADDR str4, ADDR filename
; try to open the file
INVOKE fopen, ADDR fileName, ADDR modeStr
mov pFile,eax
.IF eax == 0 ; cannot open file?
INVOKE printf,ADDR str5
jmp quit
.ELSE
INVOKE printf,ADDR str6
.ENDIF
; Close the file
INVOKE fclose, pFile
quit:
ret ; return to C++ main
asm_main ENDP
END

The scanf function requires two arguments: the first is a pointer to a format string (“%s”), and
the second is a pointer to the input string variable (fileName). We will not take the time to
explain standard C functions because there is ample documentation on the Web. An excellent
reference is Brian W. Kernighan and Dennis M. Ritchie, The C Programming Language, 2nd
Ed., Prentice Hall, 1988.

时间: 2024-10-12 16:29:38

Directory Listing Program的相关文章

使用windows server2012时FileZilla客户端连接时报150 Opening data channel for directory listing of "/" 响应:425 Can't open data connection

425 Can't open data connection 和 读取目录列表失败 问题解决 这个问题主要是由于使用Passive Mode模式造成的,解决这个问题很简单: 1.在ftp服务软件中设置指定端口地址范围,允许Passive Mode使用,比如60000-60020 2.然后在ftp服务器的系统防火墙上打开这些tcp端口,比如是60000-60020,如果使用windows自带的防火墙,就一条一条的增加,20行有点麻烦,但是可以解决. 如果ftp用户较多,可以扩大端口范围. 3.如果

Camel FTP error:File operation failed: 150 Here comes the directory listing

问题:写了一个Camel的FTP传输程序,在本地Win7和Ubuntu下运行都正常,但是在Redhat中报"File operation failed: 150 Here comes the directory listing"异常 解决方法: 首先贴出修改前的代码以及错误,如下: 代码: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.s

Windows Server 2003出现Directory Listing Denied This Virtual Directory does not allow contents to be listed.的解决方案

Directory Listing DeniedThis Virtual Directory does not allow contents to be listed. 是目录权限无法访问的问题 解决方案:鼠标右键->权限->添加->高级->立即查找->从搜索结果里面点击Everyone->确定->点击完全控制(给大点权限)->确定 鼠标右键->属性->文档->删除默认文档,添加文档为index.html->确定->应用->

How do I list the files in a directory?

原文地址:How do I list the files in a directory? You want a list of all the files, or all the files matching a certain pattern, or with a certain ending, in a directory The solution Reading directories is a bit like reading files. First you open the dire

让ADS与KEIL共存 Warning: L6373W: libattrs.map file not found in System Library directory

keil链接时出现这样的问题,电脑中有同时安装ADS与Keil,那应该是他们冲突了. linking....\Obj\Hello.axf: Warning: L6373W: libattrs.map file not found in System Library directory C:\Program Files\ARM\ADSv1_2\LIB\armlib\. Library selection may be impaired..\Obj\Hello.axf: Warning: L6310

Directory Opus(DO) 11破解版安装方法(转)

DO11原版下载 32位:http://www.gpsoft.com.au/DScripts/download.asp?file=Opus11/DOpusInstall.exe 64位:http://www.gpsoft.com.au/DScripts/download.asp?file=Opus11/DOpusInstall64.exe DO11破解步骤 1.务必断开网络连接,运行Directory Opus11.10注册失败修复工具,再安装DOpusInstall64 2.将破解文件(Dir

Generating SSH keys

Generating SSH keys MAC WINDOWS LINUX ALL SSH keys are a way to identify trusted computers, without involving passwords. The steps below will walk you through generating an SSH key and adding the public key to your GitHub account. We recommend that y

【ASK】git使用中出现Permission denied (publickey).

好久没有用git了,今天突然执行了一下 $git submodule update --init --recursive =============================== 结果出现如下提示 Cloning into 'Submodules/********'... Permission denied (publickey). =============================== 由于确实好长时间没有摸过git了,一点印象都没有了.没办法,只能google了,还好一搜就得到

Redirect

In this lesson we are going to unleash what may be the coolest feature of the command line.It's called I/O redirection.The "I/O" stands for input/output and with this facility you can redirect the input and output of commands to and from files,a