|
Programming and Assembly Language Please read this Topic's rules!! |
![]() |
| LinkBack | Thread Tools | Rate Thread |
| |||
Line Incrementation Problem using a86 I'm trying to write some code that reads a file, copies and prints to a seperate file, with line numbering, ive got quite far, just dont know how to do the line numbering, if anyone could help me with it, it would be superb, thank you! Here's my code: JMP Start cr equ 13h lf equ 10h msg1 db 'Cannot Open File, Aborting Program...',cr,lf,'$' msg2 db 'Cannot Open Output File, Aborting Program...',cr,lf,'$' msg3 db 'Cannot Write Data to File, Aborting Program...',cr,lf,'$' msg4 db 'Cannot Reading from File, Aborting Program...',cr,lf,'$' FileName db 'original.txt',0 OutputFile db 'Output.txt',0 FileHandle1 dw ? FileHandle2 dw ? Buffer db ? Position dw 0 Start: mov ah,3dh mov al,0 lea dx,FileName int 21h jnc GoodOpen lea dx,msg1 mov ah,9 int 21h jmp PgmExit GoodOpen: mov FileHandle1,ax mov ah,3ch mov cx,0 lea dx,OutputFile int 21h jnc GoodOpen2 lea dx,msg2 mov ah,9 int 21h mov ah,3eh mov bx,FileHandle1 int 21h jmp PgmExit GoodOpen2: mov FileHandle2, ax ReadFileLP: mov bx,FileHandle1 mov cx,1 lea dx,Buffer mov ah,3Fh int 21h jc BadRead cmp ax,1 jz ReadOK jmp AtEOF ReadOK: mov al,Buffer cmp al,cr jb NotLower cmp al,lf ja LineNo mov al, 5fh NotLower: mov Buffer,al mov bx,FileHandle2 mov cx,1 lea dx,buffer mov ah,40h int 21h jc BadWrite cmp ax,1 jz ReadFileLP LineNo: ;here is the line number stuff BadWrite: lea dx,msg3 mov ah,9 int 21h jmp AtEOF BadRead: lea dx,msg4 mov ah,9 int 21h AtEOF: mov bx,FileHandle1 mov ah,3eh int 21h mov bx,FileHandle2 mov ah,3eh int 21h PgmExit: mov ah,4ch int 21h
__________________ |
| |||
Nothing like a few comments is there? ![]()
__________________ Any views, thoughts and opinions are entirely my own. They don't necessarily represent those of my employer (BlackBerry). |
| ||||
I'm going to have to peel out my old DOS books when I get home. I haven't done much low-level DOS style access in quite a while. Everything I do these days uses DeviceIoctl. |
| ||||
Not sure how files are handled in x86 processors. In the 8051 it would be copied byte by byte from one location to the next. Line counting would be pretty simple then .DSEG .EQU lineno,somewhere ; where somewhere is a memory location suitable for the job .CSEG ; in file handling code CJNE buffer,cr,noline ; skips the next line if not a carriage return CALL linecount noline: Rest of file handling code linecount: <move the cr and lf bytes to the output file> inc lineno ; if you're likely to have more lines than you can address, then ; you might do better with ADDC and check for overflow with JC MOV filehandle1,lineno RET This was all written after an evening in the pub, so is also completely untested ![]()
__________________ It is by coffee alone I set my mind in motion... Last edited by Kaitain; 8th May, 2004 at 12:40 AM. |
| ||||
Quote:
![]() ![]()
__________________ It is by coffee alone I set my mind in motion... |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Rate This Thread | |
| |
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Serious Help with the AMD Line | calhoun | AMD Motherboards & CPUs | 35 | 16th November, 2005 05:44 PM |
Where to plug "Line In" Device with 8RDA+ and Rear Speakers plugged in "Line In" | MegaManX4 | EPoX MotherBoards | 8 | 18th June, 2003 10:19 PM |
VERY low 3.3v line... | hp550c | EPoX MotherBoards | 16 | 12th December, 2002 06:47 PM |
Get in line | Uncle Bob | Mookydooky's Just for laughs! | 0 | 23rd June, 2002 09:15 AM |
second line in my sig | eobard | CRASHED! | 33 | 8th May, 2002 11:36 PM |