Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <a href="http://spike.scu.edu.au/~barry/interrupts.html#ah0a">function <code>0Ah</code></a> to read buffered input. Given a string buffer in <code>ds:dx</code> it reads a string of up to length 255. The buffer layout is:</p> <pre><code>Byte 0 String length (0-255) Byte 1 Bytes read (0-255, filled by DOS on return) Bytes 2-..Length+2 (The character string including newline as read by DOS). </code></pre> <p>An example of a small COM file that reads a string and then echos it back to the user:</p> <pre><code> org 0x100 start: push cs pop ds ; COM file, ds = cs mov ah, 0x0A ; Function 0Ah Buffered input mov dx, string_buf ; ds:dx points to string buffer int 0x21 movzx si, byte [string_buf+1] ; get number of chars read mov dx, string_buf + 2 ; start of actual string add si, dx ; si points to string + number of chars read mov byte [si], '$' ; Terminate string mov ah, 0x09 ; Function 09h Print character string int 0x21 ; ds:dx points to string ; Exit mov ax, 0x4c00 int 0x21 string_buf: db 255 ; size of buffer in characters db 0 ; filled by DOS with actual size times 255 db 0 ; actual string </code></pre> <p>Note that it will overwrite the input line (and it thus might not look the program is doing anything!)</p> <p>Alternatively you can use <a href="http://spike.scu.edu.au/~barry/interrupts.html#ah01">function <code>01h</code></a> and read the characters yourself in a loop. Something like this (note it will overflow later buffers if more than 255 characters are entered):</p> <pre><code> org 0x100 start: push cs pop ax mov ds, ax mov es, ax; make sure ds = es = cs mov di, string ; es:di points to string cld ; clear direction flag (so stosb incremements rather than decrements) read_loop: mov ah, 0x01 ; Function 01h Read character from stdin with echo int 0x21 cmp al, 0x0D ; character is carriage return? je read_done ; yes? exit the loop stosb ; store the character at es:di and increment di jmp read_loop ; loop again read_done: mov al, '$' stosb ; 'Make sure the string is '$' terminated mov dx, string ; ds:dx points to string mov ah, 0x09 ; Function 09h Print character string int 0x21 ; Exit mov ax, 0x4c00 int 0x21 string: times 255 db 0 ; reserve room for 255 characters </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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