Hi,
I've been trying to get my head around x86 assembly lately, and I've been working on this one problem. I'm trying to write a program that reads characters from a text file, then display them on the console. It's a simple exercise in file operations, but I'm having a bit of trouble with it!

Here's what I've got so far:

.model small
.data
			Filename db 'test.txt'
			FHndl dw ?
			Buffer db 80h dup(?)
.stack 100h
.code
Program:			 
		mov     ah, 3dh         ;Open the file
                mov     al, 0           ;Open for reading
                lea     dx, Filename    ;Presume DS points at filename
                int     21h             ; segment.
               ; jc      BadOpen
                mov     FHndl, ax       ;Save file handle

LP:             mov     ah,3fh          ;Read data from the file
                lea     dx, Buffer      ;Address of data buffer
                mov     cx, 1           ;Read one byte
                mov     bx, FHndl       ;Get file handle value
                int     21h
               ; jc      ReadError
                cmp     ax, cx          ;EOF reached?
                jne     EOF
                mov     al, Buffer      ;Get character read
                call write                    ;Print it
                jmp     LP              ;Read next byte

EOF:            mov     bx, FHndl
                mov     ah, 3eh         ;Close file
                int     21h
                ;jc      CloseError

		PROC write
		    push ax bx cx dx
		    mov ah, 2
		    mov dl, Buffer ;char to be printed
		    int 21h
	            pop ax bx cx dx
		    ret
		ENDP

				
End Program

My problem here, I think, is with my write procedure. I'm not quite sure how to go about completing this program, any help would be much appreciated!

i guess you should add these:
Filename db 'test.txt',00h
and:
mov ax,@data
mov ds,ax

how about PROC / ENDP around "Program" block - and terminate it with an int 20h or equivalent.

Also, you must POP registers in reverse order from how you PUSHed them - remember, the stack is LIFO.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.