I have this assembly code that reads a string of 120 bytes. If I try to fill the buffer by pressing a key until it stops writing, the enter key doesn't work. I counted the characters and I found that I have written 121 characters.

Is this normal? Is there a way to avoid it? Another interruption perhaps?

The code:

.model small
.stack 100h
    MSG DB "Please give me the string (max 120 chars): ", 10, 13, "$"
    Sentence1 DB 121,?,121 dup(0)
    mov ax, @data
    mov ds, ax

    mov ah,09h
    lea dx,A
    int 21h

    xor ax,ax        
    mov dx, offset Sentence1
    mov ah, 0Ah
    int 21h
    xor bx,bx
    mov bl, Sentence1[1]
    mov Sentence1[bx+2], '$' 

    mov ah, 4ch
    int 21h
end start  

An example (imagine that is a 11 bytes buffer and not 121 bytes, for brevity):

Please give me the string (max 10 chars):
    11 As

If I press Enter at this point it doesn't work, but if I delete an A and press Enter, then it works.

I use Tasm and Tlink for compiling.


[Edit] A typo.


Is this normal?


Is there a way to avoid it?

You can use Ctrl+C or Ctrl+Break to exit buffered-input mode (this results in an INT 23h).

Another interruption perhaps?

There are several DOS interrupt services that you could use to read input, but INT 21h/AH=01h is probably the next best option.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.