‫Hello and welcome.
‫And in this lecture, we will create a bootloader that outputs the text Hello World, I will be using
‫the Visual Studio Code editor for writing my code.
‫You may use any editor that you wish.
‫We will be writing in just assembly language for this lecture.
‫I'm now going to open up my text editor.
‫I'm going to go file open folder.
‫Going to select my desktop and I'm going to create a new folder and call it Peach OS.
‫This is what we will call our operating system for now on.
‫Excellent.
‫So now that the fold is open, I'm going to maximize the window and I'm going to click this new file
‫button and I'm going to create a new file.
‫I'm going to call it Boutte's Dot HSM.
‫So obviously you're familiar with the Sami language.
‫So we used Azem for assembly files.
‫I'm also going to get an extension here that can help with the Assem file parsing.
‫So I'm just going to search the marketplace.
‫And I'm going to take this one here.
‫This one looks good.
‫OK.
‫So when now ready to start writing our bootloader?
‫OK, so we first need to specify our assembly origin so that the assembly knows how to offset our data.
‫Now, if you remember correctly, I told you in the boot process lecture that the BIOS loads us into
‫address zero seven see zero zero so we can tell our Sembler to originate from that address.
‫We can do that by doing this.
‫There is a smarter way to do what I'm about to do.
‫But obviously, because this is the first tutorial, we will do it like this.
‫Ideally, the origin should be zero and then we do a jump to address six seven six zero zero.
‫There's reasons for doing that, but will go on to that later on.
‫Next, we need to tell the assembler that we are using 16 bit architecture.
‫So just to bits 16, this will ensure that the assembler will only assemble assembly instructions into
‫16 bit code.
‫Let's now create a standard label.
‫We will just use this to represent where we're actually going to be writing our code.
‫What I now need to do is I wanted to move a value into the H register.
‫So we're going to go move h zero e h.
‫So if you're used to writing Assembly and Windows and Linux and stuff like that, you'll be used to
‫doing things like Move X and all this sort of stuff, right?
‫Well, H is just a register of the register.
‫So, you know, you have the register and then they have to make those registers up.
‫Then you have the X register, right.
‫So try not to worry too much about that stuff.
‫As long as, you know, modern assembly language for X 86 systems, writing real code like this shouldn't
‫be too difficult.
‫You will pick it up.
‫So here we move Zoë Hage into the H Register.
‫Let's move character A into the URL register.
‫And now I just want you to go into zero x ten.
‫So if you're developing for Linux and Windows with a Sembler, you will know that they have their own
‫interests that you can call while the bios set up a lot of different interests for us to call.
‫So when we call in, it selects 10.
‫We are calling the BIOS.
‫That's exactly what we're doing.
‫This is what I meant when I said the BIOS is like a kernel in itself.
‫We're actually calling a biased routine by doing this right.
‫So what does this routine do?
‫We're basically saying output the character, eh?
‫To the terminal.
‫To the screen.
‫That's what we're saying.
‫So Zawi Hajj is the command to do that.
‫And A is the character a printing?
‫And if you search up Ralph Brown's Interop list, which I will do now, you can see that this guy has
‫documented all of these.
‫So if I go to interrupt here and these are all the bios interrupts remember I said it's generic, right?
‫All the bios tend to implement the same implementation.
‫So it provides a generic across the board interface while this is what I meant.
‫Right.
‫So if we press interrupt here and if we look for our command on here, here we go.
‫Video teletype output in Interop 10.
‫Age equals zero age.
‫So we collect that.
‫We can see display a character on the screen, advancing the cursor and scrolling if necessary.
‫So this is a bias routine and this is this is what we've just done now, basically.
‫Right.
‫So we've provided Zoey Hage in the register, right?
‫That's the command.
‫We've provided the character a in the URL register and we haven't set the page number or foreground.
‫But, you know, if you really want to do that, then we can just to move back to zero.
‫And that should be absolutely fine.
‫OK, so there's a little more we need to do.
‫Remember I said that we needed the boots signature five five eight on the last two bytes.
‫What we need to do that.
‫Right.
‫So go down here and we're going to go times five, ten dollar dash dollar dollar DB zero.
‫And then down here, just go W zero, x a five five.
‫Now the reason I've done a five five and not five five eight is because, remember, Intel machine's
‫a little endian, so the bicep get flipped, one working with words.
‫So this will actually be written as five five a.
‫So what is this times five 10 thing do.
‫Well it says that we need to fill at least 500 terabytes of data.
‫That's what it says.
‫So.
‫If we use 510 bytes of data in our code, then this won't output anything, right?
‫But if we don't, it'll pad the rest with zeros.
‫So let's say we only use five bytes in our code, right.
‫Then it will pad the the extra 10 bytes with zeros, so fills it to the end.
‫And this allows us to just go w and we can add about signature here.
‫W4 assemble word.
‫Basically, it will essentially just put this as binary straight into our file.
‫That's what this W does and W is for two bytes.
‫OK, so all I want you to do now then I want to go jump dollar and obviously that will make sure that
‫it will keep jumping to itself.
‫So we'll keep jumping to line ten here so that we never carry on running, running down here and trying
‫to execute our signature, which we really wouldn't want to do.
‫Once you've done that, we are ready to assemble this and run it in Kumu.
‫So open up your folder.
‫And right, click open and terminal, and we're just going to go Nazan Taseff Bill, so this means that
‫we're assembling to binary.
‫We don't want to assemble this to a object file.
‫And the reason we want to roll binary output is because the processor has no concept of executable files,
‫it has no concept of file formats, file systems.
‫So it needs to be a binary file.
‫So we're just going to go forward.
‫Slash computer RASM, Tacho.
‫Dark forward slash cooped and all the binary Farley's guys, it's just a file without headers.
‫Right, everything's condensed.
‫There's no head, there's no head information, none of that stuff, it's just the raw code outputted
‫that said, OK, and we can see his output, a file of zero bytes.
‫That's because I didn't save the file.
‫Remember to press control, guys.
‫We're going to go back, run that command again, and now you'll see five hundred and twelve bytes boot
‫boot sector here.
‫Right.
‫And if we just go and say s.m top forward slash boot up in yellow, you'll see the disassembly output.
‫So you can see there's assembly we wrote here, OK, and then we can see our infinite jump, the jumps
‫to itself and then remember what I said about that times five, 10 thing, it's filled the rest of the
‫bytes with zero.
‫OK, the bytes we didn't use and it fit said into 512 bytes.
‫So it doesn't matter if we've only written a few instructions here because this time is five.
‫Ten things will ensure that it expands our sector all the way to five to 12 bytes, which is what it
‫needs to be.
‫Because remember, about Cintia needs to be about 511 and 512.
‫OK, now for the fun stuff, we're going to actually run it.
‫So what we're going to do is we're going to go kumu system dash XLE six 64 dash hastier for hard drive
‫top forward slash boot up in just press enter.
‫And what do you see there?
‫We see a we have just made our very first boot sector that outputs the character A to the screen, you
‫can see it by there.
‫OK, cool.
‫So just try to see here now then.
‫And we're going to change this to outputs a message instead.
‫So just down by here, we're going to go message DBI.
‫Hello, World.
‫OK, so you know, this is a label called Message and we create some bytes here that say Hello World
‫and Arnold Terminator at the end.
‫As you know, we're going to take our code here that we've written and we're going to create a routine
‫and a start here.
‫And there are there are infinite jump.
‫We're just going to go print and we're just going to paste that in, OK?
‫And as a matter of fact, don't call it print, call it print char.
‫So we're just going to change that.
‫It's a print shop.
‫OK, and now just by here, we're going to go print, OK?
‫And then obviously our print will call print shop.
‫Now I want you to remove the the movie a always remove that OK item, remove move be zero.
‫And we're just going to put movie zero in our prints.
‫OK, and down by here I want you to do Wrex because this is now going to be a subroutine and we need
‫to return from it.
‫OK, great.
‫Now before we do anything else on line five here, we're just going to go move essi message.
‫OK, so our size the register as well.
‫And what we're essentially saying moved the address of the label message into the ASI register.
‫Right.
‫And then we're just going to go call friends.
‫So that'll print our message basically.
‫Right.
‫Obviously now it doesn't, but it will.
‫So we're just going to go right by here to return from the subroutine for prints for when they call
‫print.
‫And we're just going to go a a lot aspy and what the Lord Espie instruction will do, it will load the
‫character that the ASI register is pointing to, such as Haiti, for example, and it will load it into
‫the P&L register and then it will increment the ASI register.
‫So then it points to E and if we call ODP again, it'll incremented again, it'll now point to Al and
‫so on.
‫So that is how long the works.
‫And that is why we removed Daniel here, because lot S.P. loads that character from where the ASI is
‫pointing in memory.
‫It loads it into the URL register.
‫So in Nazeem you can make sort of like these sub labels, right.
‫Labels that only apply to the label above them.
‫So how we do this is we just put a dot at the start of our label, so we're just going to go dot done.
‫OK, now just after Lordsburg, we're going to go copy for compare.
‫Compare.
‫Al with zero, right, and then we're going to say, if it's equal to zero, then jump to done J.E.,
‫you know, jump equal.
‫Now everything under this line is if Al is not zero, because remember, here we have our zero, which
‫signifies the end of our string.
‫Right.
‫So we're going to do is we're going to say call Prince Charles.
‫OK, now, obviously, this is going to end up running into done and then we're going to leave.
‫We don't want that.
‫So just just by here, we're going to have to make another label when I call it dot loop, OK?
‫And then we're going to go Jeb dot loop by here, OK?
‫Now, let's just test this, and if all works, I will explain it to you.
‫So we're going to go back to our terminal.
‫We are going to run our command again.
‫And we're going to run kumu again.
‫And we see hello, world amazing.
‫You just wrote your very first message out to the screen.
‫So how that works then?
‫Let me let me explain it again.
‫We move the address of our message label into the ESSI register.
‫OK, we call our print subroutine, which comes and jumps down here.
‫We set back to zero for the page number and stuff.
‫Right.
‫And then we call ODP Lordsburg, says, OK, let's go here and see where our Assai register is pointing.
‫RSI Register is pointing here.
‫So we take a page, we put it into the P&L register.
‫Now we say, is the IRS to zero?
‫Well, it is.
‫And zeros.
‫So we we don't jump to them.
‫Instead, we call print, which jumps down here, sets a page to Zoey Hajj, because that is the function
‫for outputting to the to the screen when when talking with our bios, we then call interrupt zero x10,
‫which will invoke the bios.
‫The bios will see zui hech it knows we want to output a character.
‫It takes the character from the P&L register and outputs it to the screen.
‫OK.
‫At this point in time, the ESSI register is now message plus one, so it points out a.
‫On the next loop around, because it goes jump loops or jumps back on the left, on the next loop around,
‫we call Lord again, it now loads it into the Al register is e0.
‫No, it isn't.
‫So we call printshop and it repeats until it gets to zero.
‫And then we say Compar Al Jazeera.
‫Is it zero?
‫Yes, it is.
‫Jumped AdOne and we call Rete, which is means return from subroutine.