2

I want to get the number entered by the user into a register. This is my own OS. So, I cannot use this:

mov al,0x01
int 0x21
mov dl,al ;move the integer entered by the user, into dl

since int 0x21 calles ms-dos. So what interuppt can I use?

Isaac D. Cohen
  • 797
  • 2
  • 10
  • 26
  • That won't input an integer - it inputs a string of characters. Checking that the string represents a valid integer and actually converting it to that integer are additional steps that you need to perform. Assembly is low-level like that. You could, with care, arrange to call C library functions to accomplish that, including formatted input, but to do it completely in assembly means you have to take care of all the details... – twalberg Dec 27 '13 at 17:44
  • This was 6+ years old b ut if the OP is still around were you looking to do this in protected mode or real mode? A protected mode example can be found here: https://stackoverflow.com/a/37635449/3857942 – Michael Petch Jun 30 '19 at 20:52

2 Answers2

5

Depends on what your OS provides. If it's your OS, you can use anything you write.

Possibilities include checking the keyboard controller or a serial port, depending on what input you want. If your OS runs in 8086 Real Mode, you can ask the BIOS for these, otherwise you need to do direct port I/O.

If you want to program the BIOS, check the RBIL. In fact, do check it, no matter what you do.

If you want to talk directly to the KBC (keyboard controller) or UART (serial port controller), I suggest looking at how other OSes do it and reading the docs on e.g. osdev.org and the OSdev Wiki.

If you’re in Real Mode, then you can call the BIOS to wait for a keypress and read it from the keyboard buffer:

MOV AH,00h
INT 16h

The ASCII code is in AL and the scancode in AH. But if you’re not in Real Mode, there is no keyboard buffer to begin with. A keyboard driver would get the data via direct port I/O to the keyboard controller from the KBC interrupt handler, then (and buffer by itself).

mirabilos
  • 5,123
  • 2
  • 46
  • 72
  • 1
    I just want to simply get whatever is in the keyboard buffer. I'd like to know if there is an interrupt I can call and it will wait until a key is pressed, then read it from the keyboard buffer. – Isaac D. Cohen Dec 29 '13 at 03:47
  • So how does a keyboard driver get the input without a keyboard buffer? – Isaac D. Cohen Dec 30 '13 at 21:01
3

If you are running on a "regular" PC in real mode you can use int 0x10 for screen output, int 0x16 for keyboard input and int 0x13 (functions AH=2, 3, 8, 0x41, 0x42, 0x43) for disk access.

Most interrupts on a regular PC are documented quite well in "Ralph Brown's interrupt list" (search for that list in Google).

Anonymous
  • 738
  • 4
  • 14
  • 36
Martin Rosenau
  • 17,897
  • 3
  • 19
  • 38
  • 1
    Would int 0x16 wait until a key is pressed? – Isaac D. Cohen Dec 30 '13 at 00:32
  • @IsaacD. the BIOS INT 16h has functions both to check if a key was pressed, and to wait until one was pressed. It also has a 15- or 16-byte input buffer. But, as I said, it only works in 8086 Real Mode. – mirabilos Dec 30 '13 at 08:17
  • 1
    @mirabilos : The BIOS keyboard buffer is effectively 15 bytes. The 16th byte is part of the mechanism used in lieu of a count variable. The catch is that the buffer size chosen has to be a power of 2. I use such an implementation in this SO answer: https://stackoverflow.com/a/51565739/3857942 – Michael Petch Aug 28 '19 at 20:48