Is it possible to be unable to put two "physical addresses" with a distance of less than 256k in a segment?
My assembly professor asked me this. Is this the right answer:"it depends on how you set the align type(BYTE,WORD,PARA,PAGE), if you set it to BYTE the answer is NO but in other cases it's YES".

Actually, the align type doesn't impact the maximum size of the segment. In real mode, a segment has a maximum size of 64K, regardless of any other factors, and segments are always aligned on 16-byte pages. In other memory modes, things get more complex, and you can have segments of up to 4Gb in size.

in the first post, I meant 64K. Let me ask it in another way:
Usually when two addresses are closer than 64K, We say they can be in a same segment. But now we have two addresses which are closer that 64K in terms of distance, Is it possible that we fail to put them in a same segment.

Yes it is possible. A segment is determined by the address in ds register. It has nothing to do with align type. AFAIK segments are never closer than 16 bytes (one paragraph), which is the smallest amount of memory that will be returned by memory allocation function (int 21h, function 48h).

One of the things you need to see as well about segment:offset addressing is that segments can overlap; a segment can begin on any 16-byte paragraph boundary (not page, that was a careless error on my part). It has to do with the particular way in which addresses are calculated in real mode, where the physical address is computed by the system by adding the value of the 16-bit segment offset to a 16-bit local address, with the segment value being offset by four bits:

0000 0000 0000 0000          segment address
     0000 0000 0000 0000     offset address (local address)
------------------------
0000 0000 0000 0000 0000     20-bit linear address

(There is actually a 64Kbyte-16byte section of addressing space that was lost this way in the original design, when the addresses added up to more than 1Mbyte; later systems, which had 24bits and eventually 32-bits of physical addressing would call this the Real Mode High Memory Area, and MS-DOS was hacked to allow it to be used for part of the system software.)

Anyway, the point is that segment addressing in the original x86 was not a straightforward matter of having a series of separate segments one following the other, as one might assume. One aspect of this is that most linear addresses had more than one segment:offset address which could refer to it. For example, both 0000:00f0 and 000f:0000 refer to linear address 000f0.

You might ask why this was done this way. Well, at the time, memory was still very expensive, and space for addressing pins was at a premium as well. There was no expectation in 1979 that microprocessor memories would ever exceed 1Mb, never mind going into the gigabytes. To Intel's engineers, this was a simple way to extend what was really a 16-bit processor to address 20 bits of memory, which seemed a forward-thinking design at a time when home computers rarely filled the whole 64K address space of existing systems (a top of the line Apple II of the time had 48K of RAM, and cost over a thousand dollars).

I found the answer. thank you all.
When the distance is between "64k-16" to "64k", we can't put them in a same segment because there is a 16bit gap between two consecutive segments.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.