Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Actually you don't <strong>put</strong> the character in <code>ds:dx</code>, but rather you use <code>ds:dx</code> to refer to the memory address where the character or whatever data is stored, in Intel syntax it would be <code>[ds:dx]</code> (but <code>dx</code> cannot be used for memory addressing).</p> <p>So, what you need to do: store the value read from keyboard with DOS interrupt <code>21h</code> / <code>ah = 01h</code>, returned in <code>al</code> to some memory address and then refer to that memory address with <code>ds:dx</code>.</p> <p>In your code you don't store the file handle at all, and load 0 from the variable <code>file_handle</code> before write to file call, as that's how you have it initialized. And then you try to read file handle from <code>ds:0</code> (as <code>si</code> equals 0), and that doesn't make sense at all. All you need to do with the file handle is to store it (return value in <code>ax</code> after file creation/trunction) and always load it to relevant register in subsequent <code>int 21h</code> referring to that same file (write to file, read from file, close file, etc.).</p> <p>So, with the fixes below it should work (didn't test). I also organized the function call parameters to the order used by Ralph Brown's interrupt list to make it easier to understand.</p> <pre><code>.section data file db 'file.txt',0 character_read db 0 </code></pre> <p>...</p> <pre><code>% create file: mov ah,3Ch % create or truncate a file mov dx,file % ds:dx points to ASCIIZ filename xor cx,cx % file attributes. int 21h mov [file_handle], ax % file handle must be stored in memory or in a register! INPUTSTART: mov ah,1 % read character from STDIN, with echo. int 21h mov [character_read], al % store the ASCII code to memory. % unless you want to loop eternally, you can check the ASCII code and exit. cmp al,20h % space. je EXIT mov ah,40h % write to file or device mov bx,[file_handle] % file handle is just a number. mov cx,1 % number of bytes to write. mov dx,character_read int 21h jmp INPUTSTART EXIT: % here you can add some clean-up code, if needed. mov ah,3Eh % close file. mov bx,[file_handle] % here you need the file handle again. int 21h mov ah,4Ch int 21h </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload