Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!pt.cs.cmu.edu!b.gp.cs.cmu.edu!Ralf.Brown@B.GP.CS.CMU.EDU From: Ralf.Brown@B.GP.CS.CMU.EDU Newsgroups: comp.sys.ibm.pc Subject: Re: SEGMENT:OFFSET Madness Message-ID: <25add058@ralf> Date: 12 Jan 90 11:40:56 GMT Sender: ralf@b.gp.cs.cmu.edu Organization: Carnegie Mellon University School of Computer Science Lines: 63 In-Reply-To: <25821@cup.portal.com> In article <25821@cup.portal.com>, cliffhanger@cup.portal.com (Cliff C Heyer) wrote: }I realize that it is more efficient to convert }"segment:offset" in it's present form to a 20-bit real }address than to store the "real" segment number 1-16 in }the segment register. This is because currently only a }bit-shift need be done to multiply the segment by 10h. }With the real segment number in there, you'd have to }multiply it by 65536 each time to get the segment }address and consume more CPU cycles. However, this does }not justify continued use of the same words. Multiply by 65536 is also a bit-shift (16 bits). }Perhaps an astute observer could offer and explanation }that would more easily allow conceptualization of what }the current "segment:offset" really represent. Many mainframes have what is known as "base registers". To specify a memory address, you give a base register and an offset from that base register. This is precisely what the Intel 80x86 processors do. The segment register is loaded with a base address, and the offset specifies the distance (up to 64K) from that base address. That is also why programs don't use a 20-bit linear address, because they would simply have to split it up again every time it is needed. A major reason for having base registers (and one reason for the Intel segment registers) is to support an address space which takes more bits than are present in a register. If Intel had defined the segment to represent "address * 256", the 8086 would have been able to support 16M of address space at the cost of more wasted RAM (due to the graininess of only being able to start a segment every 256 bytes). Another major reason for having base registers is to allow easy relocation of code. If programs always used linear addresses, every memory reference in a program would have to be patched by the program loader to allow the program to execute at a different position in memory (on machines with virtual memory, you can play with the memory mapping instead, but the Intel family in real mode do not have virtual memory). When you have base registers, the program loader can simply set the base register to the starting location of the program in memory, and the program automatically references the proper real memory locations by specifying the offset from the base register. This is how tiny model (.COM) programs work under MSDOS. Other memory models (.EXE) need to be patched by the loader, but only need the segment register loads patched, not every single memory reference. As for naming, "segment" implies a portion. From the American Heritage Dictionary: ENTRY segment (SEG'muhnt) n. MEANING 1. Any of the parts into which something can be divided. 2. Math. A As used by Intel for the 8086, "segment" means any portion of memory up to 64K in size, starting at any address which is a multiple of 16 (under protected mode on the 80286, a segment has a descriptor which specifies its 24-bit linear starting address [it can start on any byte] and its length [1 byte to 64K bytes], and trying to access beyond the defined length causes a protection violation error). -- UUCP: {ucbvax,harvard}!cs.cmu.edu!ralf -=- 412-268-3053 (school) -=- FAX: ask ARPA: ralf@cs.cmu.edu BIT: ralf%cs.cmu.edu@CMUCCVMA FIDO: Ralf Brown 1:129/46 "How to Prove It" by Dana Angluin Disclaimer? I claimed something? 14. proof by importance: A large body of useful consequences all follow from the proposition in question.