Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with segment addressing

Status
Not open for further replies.

redwing26

Programmer
Feb 16, 2006
21
GB
Hi I have quite a good book called: windows assembly language and systems programming, anyway Im at the stage where they explain how segments started, they say that each memmory address is 8bit and that the 20 bit starting adress of the code segment(cs) is CSx16. It then goes on to high memmory and how protected mode can address over the 1M limit.......this is where I get lost.......here is the example: If we put the maximum values in CS and DS to e.g

CS=FFFF IP=FFFF

The computed 20 bit address from these = 10FFEF

I dont understand how they are getting 10FFEF could someone explain this?

They say that IP is an offset of cs , I cant seem to visualise this, they say that a 0(hex) gets added to the end of cs(this is a 4 bit value adeed on?)

cs would then be FFFF0 = 20 bits? am i on right track here

after this I get confused )

Any help on this would be greatly appreciated
David
 
Ok I have reasearched this some more adding a 0 to cs is the same as cs*16 so cs = FFF0 I then add Ip which is FFFF(this is the offset?) and this gives me the text book answer of 10FFEF. This is great but isnt this a 24bit address?

cheers )
David
 
Thanks for the link salem I will check out that wiki link, the reason I said 24bit was because i thought i read in the book that 1 hex degit is 4 bits , but I have read so much the last few days I will be getting my wires crossed )s.......yeah the 21st bit is to do with getting over the 1m limit? Just ignore that statement if its crap as I have still to read that wiki .......I have also put a post up about a stupid windows .mak makefile error Im getting .....its

SKELETON.mak(9) : fatal error U1034: syntax error : separator missing
Stop.

I read on google I need to put a : between targets and dependants .......I have tried an extra colon lots of places but i still get the same error on line 9

fn = skeleton
all:$(fn) .exe
$(fn).obj : $(fn).asm
masm $(fn);
$(fn).res : $(fn).r c
rc -r $(fn).rc
$(fn).exe : $(fn) .obj $(fn) .def $(fn) .res
link $(fn) /NOD,, , libw, $(fn) .def
rc $(fn).res

cheers for the help and references
 
Is your book by any chance somewhat old? There is a thing called the A20 wrap-around, or address-line 20 wrap-around, which works like this:

As you've discovered, in 16-bit addressing, a segment register is simply shifted left 4 bits and added to an offset register to create a 20-bit address. In very early systems there were only 20 bits in any address, and 20 address-lines running round the printed circuit boards, so if you added a segment of $FFFF to an offset of $FFFF it simply wrapped-round and you ended up back near zero again.

When the first systems with more than 20 bits of address turned up, the original intention was that 16-bit work would remain in the bottom 20-bits of address, and the 1Mb limit would be retained. But some bright spark worked out that he/she could overcome this by the means you describe. Since memory was at a premium in 16-bit world, of course this high-memory area promptly got used.

But this remained a rather sneaky trick for 16-bit world to encroach on 32-bit world, so BIOS systmes also provided a possibility of dictating whether the address-line 20 stuff would wrap around or overflow. It can be turned on or off.

It's all a bit irrelevant now. If you want to work in 16-bit world, you will probably never need to worry about addresses that high, and if you want more memory, you'll probably work in 32-bit world. Remember, in practice 16-bit world tends to stick to a 640K limit, because the rest of address-space is reserved for other purposes.

 
Thanks lionellhill,

Yeah the book is a bit old , it is windows assembly language programming by Barry Kauler. It starts of dealing with 16bit then deals with 32 bit later ). It is old but even though its to do with asemblyt I feel I know understand alot more in c direct x for instance it mentions that every window gets an id and about handles . Man there is so much that happens at low lvl , I am getting there but Im going to have to read much more if I want to be able to reverse the games I own and eventually write a bootstrap and crappy os :)

If you know of any must have books please fire away.

Cheers for taking the time to help folks! ........also that make file can anyone see what is wrong with it?

david
 
Have you heard of the Global Descriptor Table? In protected mode the segment registers do not contain an address you can do calculations on. Instead they contain an index into the GDT. The GDT contains details of all currently allocated memory, and the particular piece of information you would be interested in extracting is the base address of the relevant segment. Only the operating system has access to the GDT.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top