Click here to Skip to main content
12,999,157 members (40,965 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi everyone,

My purpose is get file name from keyboard then open and write this file in asm. Actually it is first time i interested in this language.

Here is my code
                MSG  DB  0DH,0AH, ' ENTER THE FILE NAME :-----> :  $'
                STR1 DB  255 DUP('$')
                Buffer DB 10 dup(0)
                Handle dw ?
               ; ONE  DB ?
          MOV AX,@DATA
          MOV DS,AX
          LEA DX,MSG
          MOV AH,09H
          INT 21H
          LEA SI,STR1
          MOV AH,01H
          INT 21H
          MOV [SI],AL
          INC SI
          CMP AL,0DH
          JNE READ
          LEA DX,STR1
          MOV AH,09H
          INT 21H
                mov     ah, 3dh         ;Open the file
                mov     al, 0           ;Open for reading
                mov     dx, STR1        ;Presume DS points at filename
                int     21h
                jc cant_open
                mov handle, ax              ; segment.
                mov     ah,3fh              ;Read data from the file
                mov     bx, handle
                lea     dx, offset Buffer      ;Address of data buffer
                mov     cx, 10         ;Get file handle value
                int     21h
                mov bx, handle
                mov     ah, 3eh         ;Close file
                int     21h
 MOV AX, 4C00H
 INT 21H


I am getting A2070 error on "mov     dx, STR1        ;Presume DS points at filename" line. Could you help me?
Posted 11-Mar-13 10:25am
Sergey Alexandrovich Kryukov 11-Mar-13 17:03pm
The question is incorrect because such things depend on your platform. As to the CPU, it looks line anything from 8088 to x86-64 to Itanium...
And it does not look it can work under any "real" OS, it rather looks like DOS or something similar...
Yvan Rodrigues 11-Mar-13 17:59pm
Based on the calls being made, it can be assembled into a .com file (remember those?) and should run on any 8088 or later processor running DOS or later up to and including today's 32-bit Windows operating systems. It won't run on 64-bit Windows because 32-bit Windows emulates DOS using the NTVDM subsystem, which hasn't been implemented in 64-bit Windows (as far as I know).
Sergey Alexandrovich Kryukov 11-Mar-13 18:15pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This looks OK.

To open a file you need to MOV 0x3d (open file) to the ah register, MOV the (pointer to the) filename to the DX register, and MOV the access mode bitmask (0x00 == read-only) to the al register, then call INTerrupt 0x21.

Sorry, I haven't used MASM, but I'm guessing that STR1 is not a valid pointer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 11 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100