news 2026/5/23 18:20:21

汇编语言全接触-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/5/19 11:53:22

图像分割效率翻倍|sam3大模型镜像集成Gradio可视化界面

图像分割效率翻倍|sam3大模型镜像集成Gradio可视化界面 1. 引言:从万物分割到自然语言交互 图像分割作为计算机视觉中的核心任务之一,长期以来依赖于精确的标注框、点提示或掩码输入来实现目标提取。然而,随着大模型技术的发展&…

作者头像 李华
网站建设 2026/5/8 22:05:05

零售客流分析:YOLOv9统计进店人数与动线

零售客流分析:YOLOv9统计进店人数与动线 在智慧零售场景中,精准掌握顾客行为数据是优化门店布局、提升转化率的关键。传统人工计数或红外传感器方案存在误差高、无法识别个体、缺乏空间轨迹等局限。随着深度学习目标检测技术的发展,基于视觉…

作者头像 李华
网站建设 2026/5/23 2:14:33

Z-Image-Turbo_UI界面扩展功能:添加水印、压缩等后期处理模块

Z-Image-Turbo_UI界面扩展功能:添加水印、压缩等后期处理模块 1. Z-Image-Turbo UI 界面概述 Z-Image-Turbo 是一款基于深度学习的图像生成工具,其配套的 Gradio 构建的 Web UI 界面为用户提供了直观、易用的操作方式。该界面不仅支持图像生成的核心功…

作者头像 李华
网站建设 2026/5/21 18:26:31

Z-Image-Edit动作指令测试:‘放大眼睛’真的能行吗?

Z-Image-Edit动作指令测试:‘放大眼睛’真的能行吗? 1. 引言:图像编辑进入自然语言驱动时代 随着生成式AI技术的快速发展,图像编辑正从传统依赖专业软件和复杂操作的模式,逐步迈向“以文为令”的智能交互阶段。用户不…

作者头像 李华
网站建设 2026/5/21 22:52:13

HY-MT1.5-1.8B快速部署:Docker镜像一键启动方案

HY-MT1.5-1.8B快速部署:Docker镜像一键启动方案 1. 背景与技术价值 随着多语言内容在全球范围内的快速增长,高质量、低延迟的神经机器翻译(NMT)模型成为跨语言交流的核心基础设施。然而,传统大模型往往依赖高算力GPU…

作者头像 李华
网站建设 2026/5/16 19:16:10

HY-MT1.5-7B模型压缩:如何在边缘设备高效运行的秘诀

HY-MT1.5-7B模型压缩:如何在边缘设备高效运行的秘诀 1. 引言 随着多语言交流需求的不断增长,高质量、低延迟的翻译服务正从云端向边缘侧迁移。特别是在移动设备、嵌入式系统和离线场景中,对轻量化、高性能翻译模型的需求日益迫切。HY-MT1.5…

作者头像 李华