1

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
.386
.data 
    MSG DB "Please give me the string (max 120 chars): ", 10, 13, "$"
    Sentence1 DB 121,?,121 dup(0)
.code
start:
    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):
AAAAAAAAAAA
\_________/
     |
    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.

Regards.

[Edit] A typo.

1 Answer 1

1

Is this normal?

Yes.

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.

3
  • And if you want to see the actual code behind INT 21h/AH=0Ah, see google.com/webhp?q=%22cpmio.asm%22 Commented Nov 25, 2015 at 16:22
  • 1
    see reverseengineering.stackexchange.com/questions/8911/… for the explanation - the enter key requires its own buffer slot. If you fill the buffer completely, then you can't press enter. Commented Nov 26, 2015 at 16:48
  • Thank you for your answers. Now I have it clear. I tried with Emu8086 and it worked the another way around. Seems that is because of how dosbox emulates.
    – Kuro
    Commented Nov 29, 2015 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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