Click here to Skip to main content
15,895,999 members
Please Sign up or sign in to vote.
3.75/5 (4 votes)
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
ASM
.MODEL SMALL
        .DATA

                MSG  DB  0DH,0AH, ' ENTER THE FILE NAME :-----> :  $'
                STR1 DB  255 DUP('$')
                Buffer DB 10 dup(0)
                Handle dw ?
               ; ONE  DB ?
          .CODE

BEGIN:
          MOV AX,@DATA
          MOV DS,AX

          LEA DX,MSG
          MOV AH,09H
          INT 21H

          LEA SI,STR1
          MOV AH,01H

READ:
          INT 21H
          MOV [SI],AL
          INC SI
          CMP AL,0DH
          JNE READ

DISPLAY:
          LEA DX,STR1
          MOV AH,09H
          INT 21H
OPENFILE:
                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.

READFILE:
                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

EOF:
                mov bx, handle
                mov     ah, 3eh         ;Close file
                int     21h

cant_open:

 MOV AX, 4C00H
 INT 21H


        .EXIT
END BEGIN


I am getting A2070 error on "mov     dx, STR1        ;Presume DS points at filename" line. Could you help me?
Posted
Comments
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...
—SA
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    
Yes...

1 solution

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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900