I was reading the Intel Vol. 1 Basic Architecture and it said that most programs use the flat model, but you can also use the segmented model for reliability.

I don't think I have seen any assembly code using the segmented model.
I couldn't find any snippets.

Thanks,
        Andy
Posted on 2007-07-04 12:18:15 by skywalker
iirc from my comp.architecture classes, you simply use the segment registers, to allow for access to more virtual memory, but incoherency in designs limits the practical use. It's not used in neither windows nor linux. Reliability... I don't understand what they mean with it.
Posted on 2007-07-04 12:41:44 by Ultrano
Intel says that placing a program's stack in a separate segment prevents the stack from growing into the code or data segment and overwriting instructions or data.

Proper coding and checking would probably do the same thing.
Posted on 2007-07-04 12:49:30 by skywalker

Intel says that placing a program's stack in a separate segment prevents the stack from growing into the code or data segment and overwriting instructions or data.

The same can, mostly, be prevented by keeping stack and code/data far apart, having 'guard pages' where the stack grows naturally, and a range of non-present pages to trap an over/underflow... and avoid the management overhead of segments.

Posted on 2007-07-04 18:05:23 by f0dder


Intel says that placing a program's stack in a separate segment prevents the stack from growing into the code or data segment and overwriting instructions or data.

The same can, mostly, be prevented by keeping stack and code/data far apart, having 'guard pages' where the stack grows naturally, and a range of non-present pages to trap an over/underflow... and avoid the management overhead of segments.



Do you have an example of some code showing that ?

Thanks.
Posted on 2007-07-04 18:56:33 by skywalker
You're pretty much in the realm of systems-level coding with your questions, so it's hard to come up with a little snippet that'll work under windows ;)

Posted on 2007-07-04 19:01:51 by f0dder
skywalker:

Unless you are dealing with 16-bit code; or perhaps you are developing your own OS (or anything else along those lines) there is no need to play around with segmented architecture.  However, here is a very small snippet how to change to a different segment (defined by your code) within the 16-bit world


DSEG segment

Var1 DW ?
Var2 DB ?

DSEG ends

...
mov ax, dseg ;Loads ax with segment address of dseg
mov es, ax    ;set es register to point to our defined data segment
xor ax, ax
mov es:Var1, ax ; Set Var1 to the value of 0


not sure if that is what you are looking for but I hope it helps.

BTW:  One handy item to have while you dig through those books is the MASM manual, which you can obtain (in electronic format) either by doing a quick google search or you can PM with your email address and I can send it to you along with some real world examples (I don't have access to my dev system right now so I can not do it for a few days).

Have a great week

Posted on 2007-07-04 20:11:15 by madprgmr
madprgmr: edited your post and added code tags, hope you won't mind :)
Posted on 2007-07-05 03:59:34 by f0dder
Thanks gentlemen for the help.

Posted on 2007-07-05 05:26:13 by skywalker
skywalker:

Your welcome.

f0dder:

I don't mind at all, in-fact I appreciate the correction!

Posted on 2007-07-05 11:13:47 by madprgmr