Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASM
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
.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 11-Mar-13 11:25am
sesenyg399
Comments
Sergey Alexandrovich Kryukov at 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 at 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 at 11-Mar-13 18:15pm
   
Yes...

1 solution

Rate this: bad
good
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.
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 515
1 Maciej Los 340
2 Richard MacCutchan 265
3 BillWoodruff 225
4 Mathew Soji 155
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 11 Mar 2013
Copyright © CodeProject, 1999-2014
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