‫Hello and welcome in this lecture, we are going to improve our bootloader by setting up segment registers
‫and changing our program's origin when the biospheres first loads us, we don't know what the segment
‫registers are because of this.
‫By having a bootloader like we have now, there's no guarantee it'll successfully boot on most systems.
‫For example, if the bias sets our data segment to zero seven zero and our assembly program's origin
‫is zero seven six zero zero, then the equation will be dealt will be D.S. multiplied by sixteen plus
‫zero seven zero zero.
‫So FDX is zero seven zero.
‫Then we end up with this.
‫Which does not point to our message.
‫Because of these types of scenarios, it makes sense for us to initialize the data segment and all the
‫other segment registers ourself.
‫So we're going to do that here.
‫So the first thing I wanted to do is change your assembly programs origin to zero.
‫The next thing I want you to do is go to your star label and we're going to go see L.A.
‫and then under that star.
‫So I'm going to do an assembler comment here just to describe what's going on, clear interrupts.
‫So this clears the Interop flag and this enables interrupts.
‫Obviously, those youthen assembly you've probably used entraps before.
‫You know, when you're calling Linux kernel or Windows kernel, you'll go something like a..
‫You exacty something like that.
‫Right.
‫Anyway, by clearing the interim flag here, it'll disable interrupts, which is what we want because
‫we're about to change some segment registers and we wouldn't want some.
‫How we interrupt now to interrupt us while we're doing this, because this is a very critical operation,
‫like the segments won't be set up correctly and all this sort of stuff.
‫So what we're going to do is we're going to go move X zero seven zero, move does X, move s X.
‫Now, we can't just move this value directly into the data segment or the extra segment, which is why
‫we have to put in a first.
‫That's just how the process works.
‫OK, so we've set up the data segment and the extra segment.
‫So let's say that you reference message as we do here.
‫Move Essi message.
‫Right, because our origin is zero.
‫The assembler assumes that we are loaded into address zero into RAM.
‫Right.
‫So this offset will be fairly low.
‫It might be like 20 bytes or whatever it will be basically where in our binary file this is stored.
‫OK, so that, you know, it gets replaced with that.
‫Right.
‫So let's just assume that it was 20 bytes.
‫Right.
‫So I'm just kind of a 20 here.
‫Don't copy this.
‫I'm just showing you.
‫So when we did our logged SB like something like this.
‫Right.
‫What'll happen is it will use our data segment and the CI register.
‫So we do we know we've changed our data segment to zero seven zero.
‫Right.
‫So we multiply that by 16, which gives us this, OK, and then we go zero C zero zero plus twenty,
‫which gives us let me just get the calculator out to the conversion from decimal there.
‫Yes, so that gives us Hecks 14, right?
‫So then the result is zero x, C, one four, and just to confirm that, if we did the same, if we
‫did the same as you seven, we did seven zero zero.
‫Here, switch it to decimal and we add 20 and then we switch it back to hexadecimal.
‫Yes, seven C14, so that is what the process is doing, right?
‫So this is why we need to change these data segments, because if the bias set them for us, you know,
‫it could mean that our origin is set wrong for our assembly program and then it won't link up correctly.
‫Does that make sense?
‫So by changing these second registries ourself, we're taking control of the situation rather than hoping
‫that the biases set them up the way we need it to be.
‫OK, so I'm just going to control them here, put that back to what it was and then we'll set up the
‫Stack segment.
‫So the next segment, we want to set this up a bit differently because the stack grows downwards.
‫Right?
‫So what we can do is we can set the stack pointer to equal to zero seven zero zero.
‫And then obviously it will grow down.
‫As I showed in the segmentation lecture, if you if you look there for the stack section where we talk
‫about the stack, you'll see you'll see the stack described to you.
‫So what we're going to do then we're going to go move X zero zero zero, move SS X.
‫So we're set in the stack segment now to be zero.
‫OK, that's that's what we want to do.
‫And then we're going to set the stack pointer to zero seven six zero zero.
‫OK, and now that should work out fine.
‫So let's not test our program.
‫So I've opened up a terminal, I'm going to go Nazeem, FBN.
‫Top forward slash bootlace dash show, top forward slash boot top Ben.
‫And now we're going to use Kumu again.
‫And load that.
‫And we see the world so we can see that our program still works fine.
‫It does exactly what it did before, but this time we've taken control of the situation.
‫If we didn't do this and we relied on the BIOS to set these data segment, extra segment and so on,
‫for us, it might set them to zero seven C0 like we've done, or it could set them to zero and assume
‫that our origin is zero seven zero zero.
‫You really don't know what the registers are going to be when the bias closes.
‫So it's very important to take action and set these things yourself.
‫Just because it works for us in the emulator does not necessarily mean it will work on your real computer,
‫right?
‫All computers are different, so this helps increase our chances of being able to be booted on a real
‫machine.
‫And before I forget, there's one other thing we need to do.
‫We need to go jump zero seven zero start.
‫And then this will make our code segment become zero seven zero.
‫Because our origin is zero.
‫It is important our code segment is also changed to zero seven zero.
‫So by doing this, that ensures that happens.