flat assembler
Message board for the users of flat assembler.
Index
> DOS > count characters in a text file |
Author |
|
netghost 13 Jun 2005, 00:01
i m using this code but cannot understand this line "mov Buffer2,ax
add Buffer2,46 " can someone help plz??? Code: DATA segment "data" File1 db 'one.txt',0 Buffer db 256 DUP(?) Buffer2 dw 29 DUP(?),'$' DATA ends .model small .stack 1024 CODE segment "code" Assume cs:CODE, ds:DATA ep: mov AH,3Dh mov AL,0 lea dx,File1 int 21h mov BX,AX mov AH,3Fh mov CX,200 lea dx,Buffer int 21h mov Buffer2,ax add Buffer2,46 mov ah,09h mov dx,offset Buffer2 int 21h mov ah,3eh int 21h mov ax,4c00h int 21h CODE ends end ep |
|||
13 Jun 2005, 00:01 |
|
YONG 13 Jun 2005, 12:30
Your program needs to do two things:
- File I/O & Processing (i.e., counting the number of bytes read), and - Integer Outputting (i.e., printing the count). For the first thing, I suggest you read Section 13.3 "An Introduction to MS-DOS" of "The Art of Assembly Language", in particular Section 13.3.10 "Blocked File I/O" which gives some simple examples of how to do file i/o & processing. The links are: http://webster.cs.ucr.edu/AoA/DOS/AoADosIndex.html http://webster.cs.ucr.edu/AoA/DOS/ch13/CH13-8.html#HEADING8-1 For the second, check this link: http://board.flatassembler.net/topic.php?t=42 - "i wrote a Sample code for Outputting integers" by Tommy YONG |
|||
13 Jun 2005, 12:30 |
|
shaolin007 13 Jun 2005, 12:39
netghost wrote: i m using this code but cannot understand this line "mov Buffer2,ax I don't see how that code could work properly since the return value in AX after the read is the count in bytes read. Plus how is this code going to take that value and convert it to a ASCII format to print on the screen?Another problem with the program is the '$' terminating character. What if there was another character of '$' in your text file? It wouldn't read after that point if you were printing out the characters read. Best thing to do is to use a null terminated buffer and write a routine to print the contents of that buffer. Also, the carrry flag should be checked after each file operation for failure. Code: DATA segment "data" File1 db 'one.txt',0 Buffer db 256 DUP(0),0 ;zero terminated DATA ends .model small .stack 1024 CODE segment "code" Assume cs:CODE, ds:DATA ep: mov AH,3Dh mov AL,0 lea dx,File1 int 21h jc ERROR mov BX,AX mov AH,3Fh mov CX,256 lea dx,Buffer int 21h jc ERROR mov si, Buffer cld mov ah, 2 PrintString: cmp [si], 0 je Done lodsb mov dl, al int 21h jmp PrintString Done: mov ah,3eh int 21h jc ERROR mov ax,4c00h int 21h ERROR: put error routine here... CODE ends end ep I don't have MASM so I haven't tested the code. Last thing, this is a FASM board not MASM. |
|||
13 Jun 2005, 12:39 |
|
YONG 13 Jun 2005, 13:20
One more point.
If you're simply interested in the file size in bytes (rather than processing of the file content), you can use ah=4eh_int21h to do the job. Take a look at these two sections of AoA: - 13.3.8.7 "Set Disk Transfer Address (DTA)" - 13.3.8.8 "Find First File" YONG |
|||
13 Jun 2005, 13:20 |
|
netghost 14 Jun 2005, 17:47
thanks a lot guys....but still i havent figured it out....and the most worrying is that i have to give this code till tomorrow at night!!!!!!
it should be simple and maybe i should use better the file pointer using the AH=42H.... i dont know...if someone has a solid answer i would be grateful and ready to buy him a coffee in athens,greece!!!!!! p.s. i have search the net like crazy ..couldnt find something.... |
|||
14 Jun 2005, 17:47 |
|
shaolin007 15 Jun 2005, 12:09
netghost wrote: thanks a lot guys....but still i havent figured it out....and the most worrying is that i have to give this code till tomorrow at night!!!!!! We just gave you pretty much the answer. If you want to display the count, then just write a routine that converts an integer to ASCII format and then print that value to the screen. |
|||
15 Jun 2005, 12:09 |
|
Matrix 19 Jun 2005, 06:20
Hy,
well if you look around in dos thread you will find yourself complete snipplets presenting "integer to ASCII format and then print that value to the screen." if it does not matter who wrote it. netghost wrote: thanks a lot guys....but still i havent figured it out....and the most worrying is that i have to give this code till tomorrow at night!!!!!! hmm it was probably a homework, and its over by now, but was it your question to read the whole file and count bytes in a variable:that can be done with the return value "AX" of read file function and then print it on screen, or get filesize of textfile with dos function and print it onto screen? the second is easier... |
|||
19 Jun 2005, 06:20 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.