Translation/Subtitles: Anastasia Gkremou Welcome to the course of Computers’ Architecture II Last week we dealt with segmentation We’ll do some examples now, so you can fully understand how the segment’s limits are defined and how we can find a physical address when we know the addresses of the segment and the offset First of all, what is a segment? It’s a memory’s part, which has some attributes and some restrictions A code segment stores code We want to read and execute its code, but it has no sense to write and erase its instructions On the other hand, a data and a stack segment store both data But in the case of stack segment, we have also data storage but its accessing is in the form of LIFO The rights that you have on these segments are writing, reading but not executing because there’s no code to be executed in these segments In the last lesson, I told you that Intel has some registers inside the processor which define where a segment starts, they’re called segment registers There are: CS (code segment), DS (data segment), SS (stack segment) In some older processors these are 16-bit registers, while the rest are 32-bit So, we have two registers I name them symbolically, the one segment register and the other offset register If we wanted to visualize the combination between these registers in order to access a segment we could say that the segment register points at the segment’s start The segment register points at the beginning of the segment, while the offset register shows which offset we want to access inside the segment In older computers and Windows, when the system wanted to inform us that an error occured somewhere, it showed us the blue screens A frequently shown message was the segmentation fault The system showed us the address where the error occurred in the form of SEG:OFFS and that’s how we knew that the error was about the segments’ accessing The identity of the segment was separated with the colon from the offset inside the segment Before we move on to the 4th chapter, I want to show you some examples about the sizes of the segment and offset registers and how we can combine the two in order to find the physical address We’ll try to figure out some attributes in order to understand the segmentation process

Let’s assume that the values of the segment and offset are in the hexadecimal system so we won’t get lost with the binary’s zeros and aces We have a 16-bit segment register and a 32-bit offset register These are the four hexadecimal digits, which define a segment Since the 16 bits need 4 hexadecimal digits, then you realize that 32 bits need 8 hexadecimal digits Somehow the system defines the combination of the segment register with the offset register in order to form a new value Usually, the relation between these two registers includes a shift of the segment register N bits to the left We can find the physical address by doing that Whatever comes up, we do an OR operation with the offset’s value That’s how Intel handled the segmentation process Another company may have another way of finding the physical address In our example N=16 bits, meaning the shift that takes place is 16 bits to the left What does 16 bits to the left mean? It means that I put 16 zeros at the segment’s end That’s four hexadecimal digits more The 32-bit offset’s value is represented by 8 hexadecimal digits The physical address that will come up, is the result of the OR operation between these two Now, we’ll do some different variations on how we can find a physical address Based on what I have on the board, I give you these two values Let’s say that the segment’s value is 1F00h These are the four hexadecimal segment’s digits and the offset is 0010h The question is: Calculate the physical address if you know that the segment

and the offset are combined with that relation What’s the physical address? The proccess of finding is very simple, you just shift 1F00, 16 locations to the left You do that by putting four hexadecimal digits after 1F00 So, the segment is 1F00 followed by 4 zeros, OR the offset’s value and in the front I have zeros So, the physical address that defines the segment and the offset is 1F000010 If we asked from the computer to show us this physical address as a linear address it would show us this number A computer would give you this number in that form very rarely Its usual way of informing us that there’s something wrong in this address is giving us the address in that form: 1F00:0010 These two forms are completely different from one another These two numbers didn’t have an overlap in their first digits so it seems that I just putted 1F00 next to 0010 That’s not always the case I will show you some examples where it’s wrong to just put the two values next to each other We wouldn’t have the same thing if we did that Each segment’s size is 16K I’ll just say 16K and not 16KB, because the locations may not be of 1 byte If the location has 1 byte, 4 bytes or a 16-bit or 32-bit value, that it depends on the system But it has 16K locations Every segment is 64K, not 16K In order to address 64K, I need 16 bits, because 2^16=65536, which is 64K 64*1024=65536 I have 16 bits to select one of the 64K locations Let’s do a variation of that example I give you the segment’s value 1F00 What addresses exist in that segment? What we have to do is this: We shift the segment 16 locations like before, to take 1F00 and 4 zeros The offset has 16 bits, these are 4 hexadecimal digits Therefore, all can be either 0 or all F I take these values and I do the OR operation with this

The values that will come up are the limits of the physical addresses The first case is to put a zero Nothing will change and the segment’s first linear address is 1F000000 and the last is the one where I have the biggest offset inside the segment The 1F00FFFF So, the first segment’s location is 1F000000 and the last is 1F00FFFF The first and the last addresses Let’s do two more variations I give you the segment’s value and you know the physical address’ value, too Let’s assume that the physical address is 2300F000 How can we calculate the offset when we know that the segment is 1F00 and the physical address is this? What is the offset that took place in order for this particular address to come up? To make things easy, let’s say that we have an addition and not the OR operation If we were doing an addition, then we’d have to do a subtraction between the value that came up from the addition with the first known part If I shift the segment 16 locations to the left I have 1F000000 and if I do a subtraction, then what is left is the offset F doesn’t fit to 3 F is 15, if I have a carry in front of 3, then hexadecimal’s 13 is 16+3=19 In order to do the math I have to say 13 of the hexadecimal or 19 of the decimal minus 15, gives me 4 4 and carry the one Carry plus 1 = 2 2 minus 2 = 0 That’s the offset’s value that has to be added to 1F00, so I could find the physical address Now, let’s assume that the segment and offset registers have a different overlap Or let’s just do another example like this first So, let’s say that the physical address is the same as before 2300F000 and the offset has the hexadecimal address 0850A080

I know the physical address and the offset’s value, so I just have to do a subtraction between the physical address and the offset Then, I have to shift the result to the right in order to find what I’m looking for Well, B minus 0 is 11 11 minus 16, since I have a borrow, because B doesn’t fit to 0 If 1 is the borrow and 16 minus 11 = 5 5 and borrow 1+0=1 minus 0, it doesn’t fit 1 minus 16=15, that’s F in the hexadecimal Again, I have one borrow 1+A=11, therefore 11 minus 15=4 5 minus 16=11, meaning B and borrow 1+8 = 9 minus 3 It doesn’t fit, if I put an ace in the front I have 19 So, 9 minus 19=A And I have borrow Borrow minus 2=1 What is left is the segment But what I’ve just asked may be easily a trap You shouldn’t say that this is the segment’s value You should say that this value came up from the real value of the segment’s shift by 16 locations But if I shift this value to the right, I will lose 4F50 and what would be left is 1AB0 However, if I lose it, the reverse isn’t valid Meaning I wouldn’t be able to have 1AB0 and shift it 16 bits to the left then add to it the offset and eventually find that address I couldn’t have something like that, because I lost these digits So, the answer would be that something like that is not valid You can’t have these values for the physical address and the offset with a 16-bit segment and a 32-bit offset These are incompatible I’m going to change it a little bit, in order to have something valid I do the subtraction again This is the result of 1AB0’s shift 16 bits to the left This one is valid That’s the segment’s value If the system wouldn’t give me that value in a linear way it would give me the value in this form: 1AB0:0850F000

That address is equal with this This is its linear form and this is the address with separate the segment from the offset Let’s do one more example with different sizes Let’s say that the offset’s 24 bits and the segment’s 8 bits The offset is 12 bits, not 24 and the segment is 8 bits I can find the physical address If I shift the segment 8 bits and then add to it the offset’s value 8 bits are two hexadecimal digits, which I shift by 8 bits meaning I add two zeros at the end and then I add the 12-bit offset’s value The first question that I can make to differentiate this example from the previous one is: Since the offset has three hexadecimal digits or 12 binary bits then what is the size that an offset of that kind can have? The answer is 2^12=4096 Therefore, the offset’s size may be 4K The second question that I can make is: To how many segments can a physical address belongs to? Now, we have to think about the overlap that these values have, in order to find the physical address This will give us a number and from the combinations that I can have between the two numbers which will give me as a result a number, which is the answer to how many segments I can have For instance, let’s assume that we have the physical address 185A And let’s go back to the OR operation and calculate the physical address

1 belongs to the segment, because I don’t have anything in the offset 5A belong to the offset So, for the segment I know it’s 1 and something else and for the offset I know it’s something and 5A Now, I have to find the possible combinations of these two values that will give me 8 as a result There are several combinations This may be 0 and this 8 This could be 1 and this 7, 2 and 6, 3 and 5, 4 and 4 Also, the values could be reversed I couldn’t have anything else If you had a case like that, you should think all the possible combinations in order to find this particular physical address Here, we have 8 different possible combinations that can generate 8 because each digit ranges from 0 to 8 What I just did was an addition, not an OR operation If the segment and the offset were linked with an addition, then we would have 8 combinations Using the OR operation, the combinations are even less The 8 is equal with 1000 We know from the result’s OR that the segment or the offset has to be like that If at least one bit of the segment or the offset was 1, I couldn’t have 0 here So, these have to be zero We have three combinations: To have both 1, the segment to have 1 or the offset to have 1 These combinations give us three cases that I have 1 here and creating 8 I did wrongly the addition of these two, for this example early on I could have only three combinations What values can I have for the segment and the offset from these combinations? The first case is the segment to be 1 and the offset 0 so in the segment’s place I have 18 and in the offset’s I have 05A Therefore, the physical address will be 18:5A The second case is: the segment to be 0 and the first offset’s bit to be 1 Then, we would have 10 for the segment and 85A for the offset

And we would have them in the form of 10:85A The third case is to be both 1 Then, we have 18 for the segment and 85A for the offset That gives us 18:85A This example could be given to you reversed You would have to define the physical address 185A with a linear way I may told you that the segment has 8 bits, the offset has 12 bits and you would use this operation to find the physical address Nah, I may asked you if these three addresses can exist for this particular segmentation system We shift 18 by 8 locations and we do the OR operation with 5A We shift 10 by 8 locations to the left and we do an OR operation with 85A We shift 18 to the left and we do the OR operation with 85A You have to do a verification, if we have in all cases the same physical address Is it possible the segment and the offset to have reversed values? Yes, it’s possible whatever we want It’s not odd that sometimes the segment doesn’t have the bigger size than the offset Any combination is possible Usually, the segment is the smaller in size, but we shift it to the left so it takes the most significant locations of the last address That is defined by the segment register The offset register can be bigger, but most of the time we aren’t using its bigger addresses and we add only the small ones to define the least significant binary bits of the address Based on the same form, we have the segmented address in the form of 52:FA0 And we are asked to calculate this linear address It’s much easier what I’m asking you now We know these two and we’re looking for this We take 52 and we shift it 4 locations to the left, meaning we add two zeros at the end because we are in the hexadecimal system Now, we do the OR operation 0 OR 0 = 0 0 OR A = A When the two operands are both 0 then the OR’s result is 0 It’s the only case where the OR operation has a zero result The OR operation handles 0 as a neutral element so when we have a zero value OR a nonzero value, the result is the nonzero value Now the things have to be a bit analytical I write 2 and F in the binary and I do the OR operation When you have F, then whatever is the other number, the result is always F

And the last one is 5 OR 0 = 5 The address that came up from that combination is 5FA0 I could ask you to write another combination of segment and offset that has as a result the same physical address You have to think about another combination where if we do the OR operation we would have as a result F The things are even simpler than what you imagine Since, F is the dominant one, then whatever number I would put in the position of 2 the result would be the same Therefore, 53:FA0 would have the same physical address, the same applies to 57:FA0 etc In all cases I would have the same result You could alter this digit and put here F and whatever here Then, we would have combinations like 5F: and whatever you like followed by A0 All the results would be the same

You Want To Have Your Favorite Car?

We have a big list of modern & classic cars in both used and new categories.