Page 1 of 1

What does 'mov ah, 0x0e' mean and do?

Posted: Fri Nov 25, 2016 2:44 pm
by jordanbaron12
I am learning to make a very basic operating system. (I'm only 13) But I don't understand something. What does mov ah, 0x0e mean and why is it needed to print characters on the screen?

Re: What does 'int 0x10' mean and do?

Posted: Fri Nov 25, 2016 3:12 pm
by Octocontrabass
jordanbaron12 wrote:What does int 0x10 mean
The INT instruction calls an interrupt handler.
jordanbaron12 wrote:and why is it needed to print characters on the screen?
You don't need INT 0x10 to display characters on the screen.

Re: What does 'mov ah, 0x0e' mean and do?

Posted: Fri Nov 25, 2016 3:26 pm
by jordanbaron12
Oh shoot. Wrong line of code. I'm sorry, I edited my post so you can delete your reply.

Re: What does 'mov ah, 0x0e' mean and do?

Posted: Fri Nov 25, 2016 4:20 pm
by Schol-R-LEA
It's still basically the same answer, because INT 0x10 is the interrupt vector for the majority of the standard BIOS routines; the value 0x0E (which is 14 decimal) is the number of the specific Basic Input/Output Service (BIOS) operation known as "Teletype Output", which puts a single character in into the current text video buffer and advances a hidden pair of x,y values by one.

In other words, it prints one character of text the the console in text mode, and moves the cursor to the next position.

However, as Octocontrabass said, it isn't actually necessary; it just happens to be convenient when writing a boot loader, because, well, it's already there to be used. It isn't the only way to write text to the console, nor the best way, or even a particularly good way, but it is the easiest way when you are trying to cram as much as you can into a 512 byte boot sector, so if your boot loader is sending something to the text console, that's usually the way you would do it.

Mind you, most first stage boot loaders only use any text output when you are debugging them (yo would take it out later to save space, usually), and even that's assuming you are writing your own boot loader rather than using an existing one such as GRUB or BootMagic - which is what we usually recommend, as writing the boot loader is a lot of work for very little real payoff when designing a new OS.

I am among those who say that it is a useful exercise when starting out, but only as an exercise, and only to the point where you can load another sector and jump to it. Beyond that, unless you are planning to do something really, really unusual, rolling your own boot loader is sort of a waste of time.

Getting back to the issue at hand, you would usually only use the BIOS for the very start of an operating system, especially if you are planning to run it in 32-bit or 64-bit mode - the BIOS routines only work in 16-bit mode, and while there are ways to step down to 16-bit mode from 32-bit mode, doing that is both terribly inefficient and is more work than writing a proper 32-bit driver would have been in the first place.

TL;DR: INT 0x10 has several parts, and putting 0x0E in AH tells it which one to use. But you only need to know that for the very start of things anyway, and probably not even then.

Re: What does 'mov ah, 0x0e' mean and do?

Posted: Mon Nov 28, 2016 8:33 am
by Ycep
(I'm only 13)
Am I the only one who notices that this guy insults himself?

Re: What does 'mov ah, 0x0e' mean and do?

Posted: Mon Nov 28, 2016 9:17 am
by MichaelFarthing
To describe someone as 13 cannot be seen as an insult. I mean, I was 13 once!
He is simply looking forward to the even greater distinction of being 14.

(Starts going downhill after that...)

Re: What does 'mov ah, 0x0e' mean and do?

Posted: Wed Dec 07, 2016 4:28 am
by NunoLava1998
jordanbaron12 wrote:I am learning to make a very basic operating system. (I'm only 13) But I don't understand something. What does mov ah, 0x0e mean and why is it needed to print characters on the screen?

Interrupt 10h needs a value in AH/AL/AX to know what to do. To print characters on the screen, int 10h needs AH set to 0x0e.
"mov ah, 0x0e" is simply telling NASM to "Hey, please move the byte 0x0e to the register "ah"."