news 2026/5/7 13:33:41

汇编语言全接触-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/29 16:23:24

DeepSeek-R1-Distill-Qwen-1.5B低成本方案:NVIDIA T4实现每秒10次推理

DeepSeek-R1-Distill-Qwen-1.5B低成本方案:NVIDIA T4实现每秒10次推理 1. 引言 随着大模型在实际业务场景中的广泛应用,如何在有限硬件资源下实现高效、低成本的推理部署成为工程落地的关键挑战。DeepSeek-R1-Distill-Qwen-1.5B作为一款轻量化且性能优…

作者头像 李华
网站建设 2026/5/1 6:39:08

AB实验提升显著性 之 概率转换神器 P2BB

在 A/B 实验的决策环节,数据科学团队和业务团队之间常存在一道难以逾越的鸿沟。业务方关心的是“B 策略比 A 策略好吗?好多少?”,而统计学给出的答案往往是“P 值等于 0.06,差异不显著,无法拒绝零假设”。 …

作者头像 李华
网站建设 2026/5/2 5:46:00

避开“排名陷阱”:科学戒除孩子网瘾的三大核心路径

——基于16年家庭教育指导经验的深度分析 引言:当“网瘾”成为家庭教育的头号难题“孩子一回家就抱着手机,作业拖到凌晨,成绩直线下滑”“说两句就摔门,亲子关系降到冰点”“沉迷游戏、短视频,甚至出现抑郁倾向”………

作者头像 李华
网站建设 2026/4/23 14:45:35

MaxKB知识库系统对接PyTorch镜像,实现本地大模型快速接入

MaxKB知识库系统对接PyTorch镜像,实现本地大模型快速接入 1. 背景与需求分析 随着大语言模型(LLM)在企业级应用中的广泛落地,如何高效地将私有化部署的模型与业务系统集成,成为技术团队面临的核心挑战之一。MaxKB作为…

作者头像 李华
网站建设 2026/5/4 21:25:54

Jupyter一键启动Qwen3-1.7B,环境配置全搞定

Jupyter一键启动Qwen3-1.7B,环境配置全搞定 1. 引言:为什么选择在Jupyter中快速调用Qwen3-1.7B? 随着大语言模型的普及,越来越多开发者希望以最低门槛体验前沿模型能力。Qwen3(千问3)是阿里巴巴集团于202…

作者头像 李华
网站建设 2026/4/27 22:32:52

双非本科,非科班,拿下 2 个互联网大厂 Offer!

大家好,我是R哥。今天我又来分享一个励志的辅导案例,这兄弟基本信息如下:年龄:马上快 35⼯作年限:10年学历:双非本科/非科班薪资:20k核心诉求:进大厂,薪资达到40w说实话&…

作者头像 李华