在汇编器中写入文件 [英] Writing to a file in assembler

查看:146
本文介绍了在汇编器中写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是创建一个程序,该程序将一些字符串写入文件.到目前为止,我想到了这个:

I'm tasked with creating a program that would write some string to a file. So far, I came up with this:

org     100h

mov     dx, text
mov     bx, filename
mov     cx, 5
mov     ah, 40h
int     21h

mov     ax, 4c00h
int     21h

text db "Adam$"
filename db "name.txt",0

但是它什么也没做.我正在使用nasm和dosbox.

but it doesn't do anything. I'm using nasm and dosbox.

推荐答案

您必须先创建文件(如果已存在则打开文件),然后编写字符串,最后关闭文件.下一个代码是MASM,是使用EMU8086制作的,我将其发布,因为它可以帮助您理解操作方法,中断和参数相同,因此算法:

You have to create the file first (or open it if it already exists), then write the string, and finally close the file. Next code is MASM and made with EMU8086, I post it because it may help you to understand how to do it, interrupts are the same, as well as parameters, so the algorithm :

.stack 100h
.data

text db "Adam$"
filename db "name.txt",0
handler dw ?

.code          
;INITIALIZE DATA SEGMENT.
  mov  ax,@data
  mov  ds,ax

;CREATE FILE.
  mov  ah, 3ch
  mov  cx, 0
  mov  dx, offset filename
  int  21h  

;PRESERVE FILE HANDLER RETURNED.
  mov  handler, ax

;WRITE STRING.
  mov  ah, 40h
  mov  bx, handler
  mov  cx, 5  ;STRING LENGTH.
  mov  dx, offset text
  int  21h

;CLOSE FILE (OR DATA WILL BE LOST).
  mov  ah, 3eh
  mov  bx, handler
  int  21h      

;FINISH THE PROGRAM.
  mov  ax,4c00h
  int  21h           

这篇关于在汇编器中写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆