Search code examples
assemblyx86-16tasmemu8086

Assembly 8086 read number from keyboard


How can I read number from keyboard(assume that the number can be from 0 to 65535) and put value in AX register using DOS interface? Result should be same as if we would just write MOV ax, 65535 for example. I tried to do it by myself, but it didn't worked out. I'd like to see a code as an answer


Solution

  • This isn't straightforward in assembly. You'll need to make use of routines provided by either the OS or the BIOS in order to read a character and then build on top of this.

    You've tagged the question with emu8086 which claims to have a DOS interface. In that case you can use int 21h with ah set to either 1 or 7 to read a character. You'll then have to check it's a valid number character and then loop around reading more values until done. There's a int 21h reference here which should help.