0

I am learning assembler this year and I don't know how to print a string from a text file how to do that??

I am learning in the program notepad++ and run the program in dos box 8086

Thanks for the helpers..

proc OpenFile
; Open file for reading and writing
    mov ah, 3Dh
    mov al, 2
    mov dx, offset filename
    int 21h
    jc openerror
    mov [filehandle], ax
    ret
openerror:
    mov dx, offset ErrorMsg
    mov ah, 9h
    int 21h
    ret
endp OpenFile
proc WriteToFile
; Write message to file
mov ah,40h
mov bx, [filehandle]
mov cx,12
mov dx,offset user_name
int 21h
ret
endp WriteToFile

proc CloseFile
       doPush ax,bx
; Close file
mov ah,3Eh
mov bx, [filehandle]
int 21h
doPop bx,ax
ret
endp CloseFile

And how to read and print from a text file??

Fifoernik
  • 9,779
  • 1
  • 21
  • 27

1 Answers1

2

Add a procedure to read, similar to the one you got for writing.

proc ReadFromToFile
; Read message from file
mov ah, 3Fh
mov bx, [filehandle]
mov cx, 12
mov dx, offset user_name
int 21h
ret

Now if the user_name were "Supermannix$" (do notice the $ character at the end!), you can print it to the screen using

mov dx, offset user_name
mov ah, 09h
int 21h

One of your previous questions received a good answer by Sep Roland but I don't see that you've learned from it. Meaning your current OpenFile procedure still exhibits the same error reporting problem for which you got a solution in that answer - which by the way you could have accepted by now! (Just click on the checkmark on the left)

Fifoernik
  • 9,779
  • 1
  • 21
  • 27
  • But every time that I put a new input with the interrupt 21 its run over the value that was last time in the text file.. What to do?? – נדב אשד Apr 29 '18 at 15:49