flat assembler
Message board for the users of flat assembler.

Index > DOS > unix2dos

Author
Thread Post new topic Reply to topic
osetnik



Joined: 11 Jun 2021
Posts: 2
osetnik
So I tried co make unix to dos (dos to unix) end line converter and tried do use stdin/stdout. This posed a problem to recognize when was end of file reached. So starting from int 21h, ah=08h to read stdin and ah=02h to write stdout, I ended up reading with func. ah=3Fh, and writing with ah=02h.

So question is this (u2d-2):
1. is there a way to get EOF with ah=02h, or similar?

If I stick with ah=3Fh, and wanted to read more than 1 byte at a time, then:
2. how do I distinguish between reading less than requested, especially 0, and EOF?

If I use ah=40h to write (u2d-3) then:
3. does it make sense to check correctness of writing to stdout?
4. if I check then how do I know separate recoverable writing "error" from irrecoverable?

u2d-2:

Code:
;
; read from stdin and write to stdout replacing '\n' with '\r\n'
;
format MZ

main:
        push    cs
        pop     ds
L1:
        mov     dx, buf
        mov     ah, 3Fh
        mov     bx, STDIN
        mov     cx, 1
        int     21h     ; read char from file into buffer
        cmp     al, 0   ; number of bytes read
        je      EXIT

        mov     al, [buf]
        cmp     al, LF
        je      WR_CR
WR_BUF:
        mov     dl, al
        mov     ah, 02h
        int     21h     ; write char form DL to stdout
        jmp     L1
WR_CR:
        mov     dl, CR
        mov     ah, 02h
        int     21h     ; write CR
        mov     al, 10
        jmp     WR_BUF  ; write NL

EXIT:
        mov     ax, 4C00h
        int     21h; exit program

desc db 'unix2dos',0
buf db ?
CR = 13
LF = 10
STDIN = 0
STDOUT = 1
    


u2d-3:

Code:
;
; read from stdin and write to stdout replacing '\n' with '\r\n'
;
format MZ

main:
        push    cs
        pop     ds
L1:
        mov     dx, buf
        mov     ah, 3Fh
        mov     bx, STDIN
        mov     cx, 1
        int     21h     ; read char from file into buffer
        cmp     al, 0   ; number of bytes actually read
        je      EXIT    ; exit at EOF
                        ; check for LF
        mov     al, [buf]
        cmp     al, LF
        je      WR_CR
WR_BUF:
        mov     dx, buf
        mov     ah, 40h
        mov     bx, STDOUT
        mov     cx, 1
        int     21h     ; write char from buffer to file
;       cmp     al, 0   ; number of bytes actually written
;       je      EXIT    ; do ... on unsuccessful write/-
        jmp     L1
WR_CR:
        mov     dx, _cr ; write CR
        mov     ah, 40h
        mov     bx, STDOUT
        mov     cx, 1
        int     21h
;       cmp     al, 0
;       je      EXIT
        jmp     WR_BUF  ; back to writing buf

EXIT:
        mov     ax, 4C00h
        int     21h; exit program

desc db 'unix2dos',0
buf db 0,0
CR = 13
LF = 10
_cr db 13       ; CR ('\r')
_lf db 10       ; LF ('\n')

STDIN = 0
STDOUT = 1
    


.
Post 11 Jun 2021, 19:48
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.