flat assembler
Message board for the users of flat assembler.
Index
> DOS > Need guidance for first program (file i/o) |
Author |
|
revolution 14 Jun 2010, 09:37
See the example folder in the download for some ways to write DOS programs.
|
|||
14 Jun 2010, 09:37 |
|
baldr 14 Jun 2010, 10:13
xHero,
section directive is for PE/COFF/ELF formats. Are you using DOS extender? |
|||
14 Jun 2010, 10:13 |
|
xHero 14 Jun 2010, 10:35
i'm using DOSBox.
rev: I have gone over many examples. I'm just not sure how to read in a file and output it |
|||
14 Jun 2010, 10:35 |
|
Tyler 14 Jun 2010, 10:52
If your coding for DOS, get used to using rbil. Look at int 21, ah=3D(open) and int 21, ah=3F(read). I don't code for DOS, so idk if this is the "right"/standard way to do it.
|
|||
14 Jun 2010, 10:52 |
|
Picnic 14 Jun 2010, 13:25
Hi xHero,
You might find useful this list with some basic interrupts under DOS. INT 21h / AH= 3Ch - create or truncate file. INT 21h / AH= 3Dh - open existing file. INT 21h / AH= 3Eh - close file. INT 21h / AH= 3Fh - read from file. INT 21h / AH= 40h - write to file. INT 21h / AH= 42h - SEEK - set current file position. |
|||
14 Jun 2010, 13:25 |
|
baldr 14 Jun 2010, 15:08
xHero,
Here's quick'n'dirty example of DOS I/O: this program reads standard input and copies it to standard output with rudimentary error handling. Code: org 0x100 .again: xor bx, bx ; standard input handle mov dx, buffer ; ds:dx -> buffer for data mov cx, buffer.size ; number of bytes to read mov ah, 0x3F ; DOS func: READ int 0x21 ; call DOS dispatcher jc .read_error ; CF indicates error test ax, ax ; ax==0 if EOF jz .done mov cx, ax ; number of bytes read otherwise inc bx ; standard output handle (1) mov ah, 0x40 ; DOS func: WRITE int 0x21 ; call DOS dispatcher jc .write_error ; CF indicates error cmp ax, cx ; number of bytes written je .again ; warning: number of bytes written != number of bytes read mov cx, warn_incomplete_write.size mov dx, warn_incomplete_write .error: mov bx, 2 ; standard error handle mov ah, 0x40 int 0x21 .done: ret .read_error: mov bx, err_read.code ; offset of error code placeholder mov dx, err_read ; in this message mov cx, err_read.size ; message size .convert_error_code: aam 16 ; split error code into ah:al cmp al, 10 ; convert low nibble sbb al, 0x69 das xchg al, ah ; move converted char to its place cmp al, 10 ; convert high nibble sbb al, 0x69 das mov [bx], ax ; place converted error code in message jmp .error .write_error: mov bx, err_write.code ; see read_error mov dx, err_write mov cx, err_write.size jmp .convert_error_code warn_incomplete_write db "Warning: write not completed successfully.", 13, 10 .size = $-warn_incomplete_write err_read db "Error: read completed with code " .code db "00" db ".", 13, 10 .size = $-err_read err_write db "Error: write completed with code " .code db "00" db ".", 13, 10 .size = $-err_write buffer rb 512 .size = $-buffer |
|||
14 Jun 2010, 15:08 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.