‫So we recently discussed registers and I went over the registers briefly, but this lecture will go
‫a lot more in depth.
‫We'll work with segment registers and I'll show you how they all work.
‫So to start, what I wanted to do is I wanted to go MLV bracket by here.
‫I wanted to do zero X if another bracket here and then we're going to go thirty.
‫No, no, no, don't you.
‫32 zero x 30.
‫So it's hexadecimal says a little easier to read.
‫So what we do is we move hexadecimal 30 into address XRF or 205.
‫Now just to show how this works, I want you to press emulate.
‫I want you to press single step once brilliant.
‫And now down here you will see memory in view memory and you'll see this nice window.
‫Now here to the right, you'll see 105 or it might be a different number for you.
‫Change this to F and press update.
‫And now inside here you can see hexadecimal 30.
‫So we've moved hexadecimal 30 to address F F.
‫However, it is based on our data segment register, which is at zero seven zero zero hex.
‫So what happens is the value we put here, offsets from that from that address.
‫So the way you can calculate the absolute address is by taking our segment value, which is zero seven
‫zero zero, multiply it by sixteen and then add our offset, which is zero Zef to that number.
‫And that is the absolute address in RAM where this value is stored.
‫So we haven't really set the value at zero and address Yossef, address 255.
‫We've set it at the real address of zero seven zero zero hex multiplied by sixteen plus 255 decimal.
‫That is where we set it.
‫So if we want to change our data segre register by doing this movie, X will set it to I don't know,
‫let's to three hundred.
‫Yeah.
‫And then we go move this X for data segment and we emulate that now.
‫And I want you to do a single step that moves zero three zero zero into the X register here to single
‫step again that moves it from X or copies that I should say from X into the data segment register and
‫now do a single step to make that right.
‫Now, if we go back to memory, you'll see if you left here, you don't see the value, but if you now
‫change this to three zero three zero zero.
‫Press update, you see our 30 Hecks, so what we've done there, we move where the data segments pointing
‫to so that any rights to any relative addresses will take into account that data segment.
‫So now zero six thirty is stored at zero three zero zero, multiplied by 16 plus, if not zero seven
‫zero zero multiplied by 16 plus F..
‫But there the physical address, the real address is right.
‫And the reason we need this segmentation is because sixteen bits or two bytes, which is the size of
‫all of the registers here, cannot hold the full address that they're too small, which is why we use
‫segmentation.
‫Right.
‫So hopefully that makes sense.
‫So what we've done here, we've moved Xerox three hundred into our X register.
‫We then move the X register.
‫When I say move, I mean copy, by the way, into the data segment register now because the data segment
‫registers changed any rate.
‫So we do the memory will take into account where the data segment is pointing to.
‫So basically that is why this is where our third is.
‫It's no longer at zero seven hundred with an offset of if it is now at zero three hundred with an offset
‫of F, OK, so hopefully that makes a lot of sense.
‫Now I know you're already asking this question, why don't we just do this move Xerox.
‫Three hundred the well if you try that it'll fail.
‫And that's because the 86 six instruction set doesn't have an instruction for doing this, because remember,
‫assembly language is just a human readable way of writing machine code.
‫Right.
‫The processor doesn't have a way to do that.
‫So the assembler isn't going to put that in for us.
‫You know, that's not the whole point.
‫The whole point of assembly is to mimic machine code on a human readable level.
‫So if we was to do move a Xerox 300 and then move X into D, that is an acceptable instruction.
‫If we did this, there is no option in the instruction set for mediates so that that would not work.
‫And when I refer to a medium, I'm talking about literal numbers like numbers that are defined during
‫assembly time, like zero x 300, by the way, that that is an immediate value.
‫OK, so if we look at the instructions said, use this as a resource because it tells you everything
‫that the that the processor can do, it tells you what it can't do.
‫You need to follow these rules because it won't work.
‫You see, it says here the move instruction cannot copy immediate value to segment register, should
‫copy the general register first, which is the reason why we copy it into our general register X before
‫copying X to D.
‫OK, so that that's basically segmentation.
‫We also have code segments as well.
‫And this this works the same in the ways the data segment does.
‫What I just explained, apart from it, also applies to this IP.
‫So remember, the IP is the program counter which instructions running in memory currently.
‫So this is zero zero zero zero.
‫What is actually running is this code segment multiplied by sixteen plus zero.
‫That's the physical address it's running.
‫So I now want to show you how you can jump to another section of code and what the jump does.
‫Guys, it just writes the execution, right?
‫So, for example, before we do that, let me make a little label here.
‫If I did test and then he up here.
‫I did.
‫Jump on the school test will put on school here, guys, because key Keywood, if I did this, all of
‫this does is it changes the IP, the IP register.
‫It's a pointer here so that it runs code from here.
‫Right.
‫That's that's all the jump does.
‫It allows me to reroute execution.
‫So now I've explained that there's something I wanted to show you.
‫I wanted to show you how you can jump from one segment to another.
‫It's pretty, pretty handy.
‫Right.
‫So if I did jump zero seven zero and then here I did Zef.
‫Now we press emulate and before we press emulate, let me go to this, OK?
‫We don't need that anymore.
‫So I to emulate and now I want you to single step the jump and you'll see our code segments changed
‫and our approach has changed.
‫So our IP register, which is the current instructions being executed, is now FF, which is the offset
‫from the from the code segment.
‫Right.
‫And our code segment is now at seven zero.
‫So if I quickly opened up a calculator and I'm going to press Hecks here, I'm going to type seven C0
‫and I want to change, that's a decimal and I'm going to multiply that by 16 and now I'm going to click
‫Hecks again.
‫You can see that gives us seven zero zero five now plus if you can see seven C CFF.
‫So that is the physical address that we are jumping to.
‫And then obviously the process will read the value from this address and that is our instruction.
‫It's going to execute.