AOA Forums AOA Forums AOA Forums Folding For Team 45 AOA Files Home Front Page Become an AOA Subscriber! UserCP Calendar Memberlist FAQ Search Forum Home


Go Back   AOA Forums > Software > Programming and Assembly Language

Programming and Assembly Language Please read this Topic's rules!!


Reply
 
LinkBack Thread Tools Rate Thread
  #1 (permalink)  
Old 5th May, 2004, 09:26 PM
Member
 
Join Date: May 2004
Posts: 1

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
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 5th May, 2004, 10:57 PM
Chief Systems Administrator
 
Join Date: September 2001
Location: Europe
Posts: 13,075

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).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 5th May, 2004, 11:16 PM
Gizmo's Avatar
Chief BBS Administrator
BassTeroids Champion, Global Player Champion, Aim & Fire Champion, Puzzle Maniax Champion, Othello Champion, Canyon Glider Champion, Unicycle Challenge Champion, YetiSports 9: Final Spit Champion, Zed Champion
 
Join Date: May 2003
Location: Webb City, Mo
Posts: 16,178
Send a message via ICQ to Gizmo Send a message via AIM to Gizmo Send a message via MSN to Gizmo Send a message via Yahoo to Gizmo Send a message via Skype™ to Gizmo

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 5th May, 2004, 11:38 PM
Kaitain's Avatar
Member
Mars Rover Champion, Joust Champion
 
Join Date: September 2001
Location: MK10, UK.
Posts: 4,372
Send a message via MSN to Kaitain Send a message via Skype™ to Kaitain

Glad to see Intel have moved on so far since the 8051
__________________
It is by coffee alone I set my mind in motion...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 7th May, 2004, 09:40 AM
Allan's Avatar
Member/Contributer
 
Join Date: September 2001
Location: Denmark
Posts: 7,914

Why don't you put the messages and variables in the .DATA segment instead of the .CODE segment? Then you wouldn't need a JMP Start command.

As mentioned you really should use comments more, it took me a while to read through your program. Some line breaks before every label would be good too.

My initial solution to your problem would be to make an array, put the line number in the first array position, then a space, and then add the line.

Line number itself could just be a variable (a DW is probably enough) that you increment (INC) after every insertion.

Sorry, I haven't messed with file handling in assembly so thats the best I can think of right now.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 7th May, 2004, 09:29 PM
Kaitain's Avatar
Member
Mars Rover Champion, Joust Champion
 
Join Date: September 2001
Location: MK10, UK.
Posts: 4,372
Send a message via MSN to Kaitain Send a message via Skype™ to Kaitain

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 7th May, 2004, 11:50 PM
danrok's Avatar
AOA Staff
 
Join Date: March 2003
Location: Great Britain
Posts: 18,917

Why does this program always result in a crash?

If glass is empty then
goto bar
repeat until time = '23:30'
__________________
Desktop PC: AMD FX-8370E / Asus M5A99X Evo R2.0 Motherboard / 16GB DDR3 RAM / GeForce GTX 970
AOA Team fah
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 7th May, 2004, 11:55 PM
Kaitain's Avatar
Member
Mars Rover Champion, Joust Champion
 
Join Date: September 2001
Location: MK10, UK.
Posts: 4,372
Send a message via MSN to Kaitain Send a message via Skype™ to Kaitain

Quote:
Originally Posted by danrok
Why does this program always result in a crash?

If glass is empty then
goto bar
repeat until time = '23:30'
Well if you will try to put BASIC into an assembler compiler (Or alternatively, if you will try to have a decent night on the booze under British laws )
__________________
It is by coffee alone I set my mind in motion...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
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


All times are GMT +1. The time now is 04:15 PM.


Copyright ©2001 - 2023, AOA Forums
Don't Click Here Don't Click Here Either

Search Engine Friendly URLs by vBSEO 3.3.0