2

I am currently trying to write a simple operating system and I am having trouble getting and returning user input. Basically because it's OS independent I can't use int21. The code that I am using now is here:

    inputChar:
        mov ah, 00h
        int 16h
        mov al, ah
        mov ah, 0Eh
        int 10h

It gets the character, but I am unable to successfully display it. I believe that it's a problem converting from some form of hex to a character output. The output when I input a character is basically a bunch of random characters.

Does anybody have any ideas for how to fix this?

Matt
  • 74,352
  • 26
  • 153
  • 180
Hirsh
  • 186
  • 1
  • 8
  • A bit of quick web searching shows that int16h in the PC bios retrieves raw key scan codes, rather than input characters. If you write code to convert a value to a series of characters representing these in hex or decimal, you could print them out. Or you could create a lookup table to convert them to characters or abbreviations (either terminated strings or fixed length) – Chris Stratton May 22 '13 at 22:22
  • 2
    [Ralph Brown's interrupt list](http://www.ctyme.com/intr/rb-1754.htm) says that int16h/00h returns the ASCII code in `AL`. Have you tried outputting that, rather than `AH` (the scancode)? – Michael May 23 '13 at 06:11
  • Yes, I think so. From the code posted wouldn't that try to output the al value, since that's what 0Eh will use? – Hirsh May 23 '13 at 14:55

3 Answers3

1

Assuming you are using BIOS Interrupts with Intel syntax:

To print a single character:

mov al, 'G' ;Copy the char's value to al. Replace G with the char you want to print
mov ah, 0x0e ;Copy the function number, in this case 0Eh, to ah.
int 0x10 ;Call the BIOS video service

Get input and print it (read char with echo):

xor ax, ax ;Make ax zero (faster than mov)
int 0x16 ;Raise the interrupt. Returns character code in al
mov ah, 0x0e ;Start Writing. Set AH to 0xe.
int 0x10 ; Call BIOS video service. Prints char.

On the second line of the first example I copied the function number to ah so that when the BIOS checks the register's value it knows what to do. For a list of common interrupt classes and functions, have a look here.

If the assembly code doesn't compile on your computer, you are probably using AT&T syntax assembly, but based on the example you provided I don't think you are.

DividedByZero
  • 4,333
  • 2
  • 19
  • 33
0

Try this? and see if you get any output

push cs
pop ds
mov ax,B800 ;video
mov es,ax
mov di,42 ;part of way along monitor
mov cx,1F
mov ah,70 ;inverse video
.print 
lodsb
stosw
loop print

signed Atari amigabot

Now if you can print out some random garbage the old keyboard buffer used to be some where around DS:SI 0000:041E

So ES:DI prints it to the screen And DS:SI is the buffer

ady
  • 155
  • 1
  • 8
  • Thanks, I got it fixed, not with that exact code, but using a similar method! Thanks for the response! – Hirsh May 24 '13 at 00:46
-2

What's the OS?

Some asm routines can access windows

OSBGET, OSBPUT, OSRDCH, OSASCI, OSNEWL, OSWRCH, OSWORD, OSBYTE and OSCLI

The other route is to mov values to eax and chuck them out in the OS

ady
  • 155
  • 1
  • 8
  • Er… what? The routines you're naming are from the [BBC Micro](http://en.wikipedia.org/wiki/BBC_Micro). They're not even remotely relevant on x86! –  May 23 '13 at 01:16
  • 1
    Thanks for the comment, but I have to use hardware interrupts since I am actually writing an operating system, so there is no access to any other software interrupts, that's why I specifically asked for something to replace 21h. – Hirsh May 23 '13 at 01:48
  • "The main question is whether you are in real mode or protected mode" http://stackoverflow.com/questions/1245809/what-is-int-21h – ady May 23 '13 at 01:59
  • 2
    The main question is whether ady is human being or a bot putting together random answers to questions on SO. – Michael May 23 '13 at 06:08
  • I am in real mode, if that helps. (Though you might be right, ady is not helpful). – Hirsh May 23 '13 at 14:00