news 2026/4/16 9:18:19

汇编语言全接触-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/4/10 22:48:57

AutoGLM-Phone实战案例:小红书美食搜索自动化流程详解

AutoGLM-Phone实战案例:小红书美食搜索自动化流程详解 1. 背景与技术概述 随着移动设备在日常生活中的深度渗透,用户对智能化操作的需求日益增长。传统手动操作手机的方式效率低下,尤其在重复性任务(如信息检索、账号管理&#…

作者头像 李华
网站建设 2026/4/15 14:30:29

YOLO11如何部署到生产环境?CI/CD集成教程

YOLO11如何部署到生产环境?CI/CD集成教程 YOLO11 是 Ultralytics 推出的最新目标检测算法,基于前代 YOLO 系列的高效架构进一步优化,在精度、推理速度和模型轻量化之间实现了更优平衡。相较于 YOLOv8 和 YOLOv10,YOLO11 引入了动…

作者头像 李华
网站建设 2026/4/15 16:40:40

基于vLLM加速的HY-MT1.5-7B翻译服务,实现高效本地化部署

基于vLLM加速的HY-MT1.5-7B翻译服务,实现高效本地化部署 1. 引言:大模型时代下的本地化翻译需求 随着多语言交流场景的不断扩展,高质量、低延迟的机器翻译服务已成为企业、科研机构乃至公共服务领域的重要基础设施。然而,传统云…

作者头像 李华
网站建设 2026/4/15 23:22:13

openmv与stm32通信实现智能车目标识别核心要点

OpenMV与STM32通信:打造智能车视觉识别的“黄金搭档”你有没有遇到过这种情况——想让智能小车自己“看见”目标并做出反应,结果主控MCU一跑图像处理就卡顿、延迟飙升?或者好不容易识别出一个红球,小车却因为数据传输出错转错了方…

作者头像 李华
网站建设 2026/3/24 15:32:45

超轻量级TTS本地部署指南|用Supertonic打造零延迟语音应用

超轻量级TTS本地部署指南|用Supertonic打造零延迟语音应用 1. 引言:为什么需要设备端TTS? 在当前AI语音交互日益普及的背景下,文本转语音(Text-to-Speech, TTS)技术已成为智能助手、语音播报、无障碍阅读…

作者头像 李华