news 2026/9/11 6:22:00

汇编语言全接触-87.Windows 95 长文件名的使用

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
汇编语言全接触-87.Windows 95 长文件名的使用

概述:

Windows 95 的长文件名给我们带来了很大的方便,本文讲述有关长文件名的使用方法。

长文件名的使用涉及到几个中断,在使用中,原先 DOS 中 INT 21H 的中断中参数有 ASC 文件名的地方,都有一个新的中断对应,如 INT 21H 的 3DH,6CH 对应 716CH (打开/建立文件),56H 对应 7156H(文件改名),41H 对应 7141H(文件删除)等等,其他参数中没有 ASC 文件名的,则使用原来的中断,如 3EH,3FH,40H (关闭/读/写)等等,一般编程中先检测系统是否支持长文件名,如果支持,则用新功能打开文件,再用普通的 3EH,3FH,40H 等对文件进行操作。本文中有几个例子,是用长文件名建立一个文件,写入一段文字,再打开文件、改名,然后删除,大家可以对应中断说明分析一下。

本程序要用到的 INT 21H 中断的 71xxH 功能如下:

INT 21H 中断的 716CH 功能:(打开或建立文件)

输入参数:

AX = 716Ch

BX = 存取模式和共享标志

Bit(s) Description

2-0 file access mode

000 read-only

001 write-only

010 read-write

100 read-only, do not modify file's last-access time

6-4 file sharing modes

7 no-inherit flag

8 do not buffer data (requires that all reads/writes be exact physical

sectors)

9 do not compress file even if volume normally compresses files

10 use alias hint in DI as numeric tail for short-name alias

12-11 unused??? (0)

13 return error code instead of generating INT 24h if critical error

CX = 文件属性

DX = 执行方式

Bit(s) Description (Table 01758)

0 open file (fail if file does not exist)

1 truncate file if it already exists (fail if file does not exist)

4 create new file if file does not already exist (fail if exists)

Note: the only valid combinations of multiple flags are bits 4&0 and 4&1

DS:SI -> ASC 码文件名

DI = 转化成短文件名后面加的编号

返回参数:CF 清除则成功

AX = file handle

CX = action taken

0001h file opened

0002h file created

0003h file replaced

CF 置位则失败

AX = 7100H 则表示功能不被支持

返回参数:CF 清除则成功

INT 21H 中断的 7156H 功能:(文件改名)

输入参数:

AX = 7156h

DS:DX -> 原来的 ASC 码文件名

ES:DI -> 新的 ASC 码文件名

返回参数:CF 清除则成功

CF 置位则失败

AX = 7100H 则表示功能不被支持

INT 21H 中断的 7141H 功能:(文件删除)

输入参数:

AX = 7141h

DS:DX -> ASC 码文件名

SI = 属性及是否支持通配符

0000h 不支持通配符,忽略属性

0001h 支持通配符

CL = 属性

CH = must-match attributes

返回参数:CF 清除则成功

CF 置位则失败

AX = 7100H 则表示功能不被支持

源程序:

;长文件名示例之一,建立文件 This is a test file.txt,写入一句文字,再关闭

code segment

assume cs:code,ds:code

org 100h

start:

jmp start1

file_name db 'This is a test file.txt',0

d_text db 'Sample text',0dh,0ah

d_text_end equ this byte

d_error db 'Create file error !',0dh,0ah,24h

start1:

mov ax,716ch

mov bx,2 ;Read and write

xor cx,cx ;Normal attrib

mov dx,0010h ;Create new file

mov si,offset file_name

xor di,di

int 21h

jb error

mov bx,ax

mov ah,40h

mov cx,offset d_text_end - offset d_text

mov dx,offset d_text

int 21h

mov ah,3eh

int 21h

int 20h

error:

mov ah,9

mov dx,offset d_error

int 21h

int 20h

code ends

end start

;长文件名示例之二,打开文件 This is a test file.txt,显示文件内容,再关闭

code segment

assume cs:code,ds:code

org 100h

start:

jmp start1

file_name db 'This is a test file.txt',0

buffer db 13 dup (0),0dh,0ah,24h

d_error db 'Open file error !',0dh,0ah,24h

start1:

mov ax,716ch

mov bx,2 ;Read and write

xor cx,cx ;Normal attrib

mov dx,1 ;Open file

mov si,offset file_name

mov di,1

int 21h

jb error

mov bx,ax

mov ah,3fh

mov dx,offset buffer

mov cx,13

int 21h

mov ah,9

mov dx,offset buffer

int 21h

mov ah,3eh

int 21h

int 20h

error:

mov ah,9

mov dx,offset d_error

int 21h

int 20h

code ends

end start

;长文件名示例之三,把文件 This is a test file.txt 改名到 This is another file name.txt

code segment

assume cs:code,ds:code

org 100h

start:

jmp start1

file_name db 'This is a test file.txt',0

new_name db 'This is another file name.txt',0

d_error db 'Rename file error !',0dh,0ah,24h

start1:

mov ax,7156h

mov dx,offset file_name

mov di,offset new_name

int 21h

jb error

int 20h

error:

mov ah,9

mov dx,offset d_error

int 21h

int 20h

code ends

end start

;长文件名示例之四,把文件 This is another file name.txt 删除

code segment

assume cs:code,ds:code

org 100h

start:

jmp start1

file_name db 'This is another file name.txt',0

d_error db 'Delete file error !',0dh,0ah,24h

start1:

mov ax,7141h

mov dx,offset file_name

xor si,si

xor cx,cx

int 21h

jb error

int 20h

error:

mov ah,9

mov dx,offset d_error

int 21h

int 20h

code ends

end start

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/9/2 22:26:52

FSMN-VAD模型下载慢?设置国内镜像源提速

FSMN-VAD模型下载慢?设置国内镜像源提速 1. 背景与问题分析 在语音处理领域,语音端点检测(Voice Activity Detection, VAD) 是一项基础但关键的技术。它用于识别音频中的有效语音片段,自动剔除静音或噪声部分&#x…

作者头像 李华
网站建设 2026/9/9 17:26:19

汇编语言全接触-88.用汇编计算圆周率

概述:用汇编语言编制计算程序并不是强项,特别是在涉及到浮点计算时,但汇编的一个好处就是速度快,所以在整数计算时可以试一下。本文的理论基础来自是电脑杂志1996年第10期,作者郭继展发表的一篇文章,作者提…

作者头像 李华
网站建设 2026/9/2 21:41:00

CV-UNet性能对比:CPU与GPU处理速度实测

CV-UNet性能对比:CPU与GPU处理速度实测 1. 引言 1.1 技术背景 图像抠图(Image Matting)是计算机视觉中的关键任务之一,广泛应用于电商、广告设计、影视后期等领域。传统手动抠图效率低下,而基于深度学习的自动抠图技…

作者头像 李华
网站建设 2026/9/2 21:44:19

LP3798ESM+LP15R060S_12V2A(24W) 集成750V SIC 原边控制+同步整流 反激电源方案

LP3798ESMLP15R060S 是24W 12V 2A 集成 750V SiC 原边控制 同步整流的反激电源方案,主打低成本、少 BOM、高可靠,核心用于中小功率恒压恒流隔离电源,尤其适配空间受限与成本敏感场景。核心应用场景应用领域典型产品核心适配点消费电子12V 小…

作者头像 李华
网站建设 2026/9/7 19:06:14

惊艳!DeepSeek-R1生成的代码逻辑清晰度实测

惊艳!DeepSeek-R1生成的代码逻辑清晰度实测 1. 引言:本地化推理引擎的新选择 随着大模型在推理能力上的持续突破,如何将高性能的思维链(Chain of Thought, CoT)能力部署到资源受限的环境中,成为工程落地的…

作者头像 李华
网站建设 2026/9/8 16:42:48

AI智能文档扫描仪开源优势:可定制化开发的企业部署教程

AI智能文档扫描仪开源优势:可定制化开发的企业部署教程 1. 引言 1.1 业务场景描述 在现代企业办公环境中,纸质文档的数字化处理是一项高频且基础的需求。无论是合同归档、发票报销,还是会议白板记录,都需要将物理文档快速转化为…

作者头像 李华