Search code examples
assemblydosx86-16

Unknown size of array in assembly 8086


I need to get a string input from user but i don't know the size of the string he would enter and i need to prepare an array in the memory as the size of the string because I'm using the interrupt 21h, ah=0ah. So my question is how to get an input of string if I don't know the size of it? Is there any other interrupt I can use? I searched but I didn't find anything.


Solution

  • I suggest you create a buffer with a fixed size and use a loop with the interrupt 21h, ah=8 for direct character input.

    That way you can check how many bytes the user enters and terminate if this number exceeds your buffer size.

    In short:

    • create a buffer with a sufficient size
    • grab a single char until
      • it is a linebreak
      • the number of entered chars will exceed your buffer
    • do not forget to zero terminate your string

    And if you really need to read the whole string you can maybe find a way to reallocate your buffer dynamically.