flat assembler
Message board for the users of flat assembler.

Index > DOS > A little help with my first real program? =)

Author
Thread Post new topic Reply to topic
JapanLover



Joined: 17 Oct 2006
Posts: 8
JapanLover
well here goes my first post...

i've been writing assembly for about 3 days now, so don't expect this to be super great coding, but i'm pretty proud of it so far...

this is supposed to be a very very very simple plain text file writer that will write line by line...

i am trying to keep the file size very very low...

the only problem i have is i can't figure out a good way to make it so that it will automatically add a line feed into the text file when i finish typing a line...

uhh...just read the code and comments you'll figure out the problem...

if you compile and run it it's easy to see the issue with the output...

any optimization tips for size or speed are very much appreciated aswell...

or bugs...

those are good too...

Code:
; very small plain text file writer

; start of code =)
org 256               ; start of all .COMs

; creat blank file
xor cx,cx             ; put zero in cx
mov ah,60             ; move 60 into ah for file creation
mov dx,filename       ; puts offset for file name into dx
int 33                ; int 33 to make file
push ax               ; pushes ax for popping later

; this part takes the input
input:
mov  bx,buffer        ; put offset of buffer into bx
mov  dx,bx            ; put offset in bx into dx aswell
mov  byte [bx],80     ; put max string size +1 into [bx]
mov  ah,0Ah           ; command thingy for get text buffer
int  21h              ; int the thingy in ah

; writes to file
add dx,2              ; add 2 to dx to skip to string
mov cl,[bx+1]         ; put string size into cl
pop bx                ; pop bx to use for file handle
mov ah,64             ; call 64 to write to a file
int 33                ; int to write to file

; check to see if nothing entered on this line
push bx               ; put bx on stack for later
cmp cx,0              ; compare characters in string to zero
jne input             ; if something typed start over from input

; close file
mov ah,62             ; put 62 in ah to close file
int 33                ; int 33 to close it

; quits
int 20h               ; we're all done, so quit!

; buffers and such
filename db 'a', 0    ; file name to use, small to save space
buffer:               ; buffer for text input, open ended    


many thanks in advance Very Happy
Post 17 Oct 2006, 04:44
View user's profile Send private message Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2
Hey,good job on that. That's impressive to have learned that much
in 3 days! I can't really help you with that because I don't know much about
call 10 for the buffer,but I'm sure somebody can help you!

Your code looks alot like my code. You haven't by any chance been reading
some of my posts have you? LOL .

I see you named yourself JapanLover. I'm a big fan of Japanese music
and video games. So,maybe we japanesy geeks think alike!
Post 17 Oct 2006, 07:36
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
I'm not familiar with this particular interrupt, not even sure if it uses standard scancodes, but I think you should have it check to see if you hit enter, and if you did, then have it display the 13 (Carriage Return) and 10 (Newline) characters.
Post 19 Oct 2006, 01:33
View user's profile Send private message Reply with quote
Maurício Pezzotta



Joined: 19 Oct 2006
Posts: 6
Maurício Pezzotta
As someone said, you'd have to display a LF and CR:

; writes to file

add dx,2 ; add 2 to dx to skip to string
mov cl,[bx+1] ; put string size into cl
add cl,2 ; adds two characters to line
add bx,cx ; points bx to end of text string
mov word [bx],0A0Dh ; writes LF and CR

pop bx ; pop bx to use for file handle
mov ah,64 ; call 64 to write to a file
int 33 ; int to write to file

; check to see if nothing entered on this line
push bx ; put bx on stack for later
int 33
cmp cl,2 ; cl was increase by two, so this should also increase
jne input ; if something typed start over from input
Post 19 Oct 2006, 13:57
View user's profile Send private message Reply with quote
JapanLover



Joined: 17 Oct 2006
Posts: 8
JapanLover
thanks all for the replies, i just got around to actually looking at them heh...

Maurício, i tried your code additions and it seems to cause the program to quit after entering just one line of text...

i'll tinker with it all more when i'm less tired...

thanks again all =)

p.s.

2, i like your simple name heh
Post 25 Oct 2006, 01:03
View user's profile Send private message Reply with quote
Maurício Pezzotta



Joined: 19 Oct 2006
Posts: 6
Maurício Pezzotta
JapanLover wrote:
Maurício, i tried your code additions and it seems to cause the program to quit after entering just one line of text...
I don't know; Tried again and works right here.
Post 25 Oct 2006, 10:30
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.