Page 1 of 1
What is the diff between CS and DS
Posted: Sat Aug 06, 2005 2:15 pm
by codemastersnake
Hello every one!
Can ne one tell me the diff between code segment and data segment a-z....
also is there any stack in real mode environment
Re:What is the diff between CS and DS
Posted: Sat Aug 06, 2005 8:08 pm
by AR
CS stands for Code Segment, it is the segment that the code is executed from. DS is the Data Segment and is where the CPU will attempt to read memory accesses from. This allows you to confuse yourself by having CS and DS at different locations, eg.
Code: Select all
.org 0x5000
ljmp 0, $Start # Set CS=0, IP=0x5005
Start:
mov $0x0700, %ax
mov %ax, %ds # Set DS=0x700
mov (0x8), %ax # Access memory implicitly through DS, meaning at 0x7008
The stack in realmode is in the SS segment, stack pointer is SP.
Re:What is the diff between CS and DS
Posted: Mon Aug 08, 2005 1:16 am
by codemastersnake
OK then how much amount of stack I can asign in rm....
can I do something like this:
--------
unsigned char _STACK[1024]; //1KB... can I asign any value...
asm mov sp, [_STACK];
------
Re:What is the diff between CS and DS
Posted: Mon Aug 08, 2005 1:47 am
by Solar
A segment in Real Mode is limited to 64k, so that's the maximum size of your stack segment.
Re:What is the diff between CS and DS
Posted: Mon Aug 08, 2005 3:01 am
by Visitor..
Codemaster Snake wrote:
--------
unsigned char _STACK[1024]; //1KB... can I asign any value...
asm mov sp, [_STACK];
------
The stack grows downwards so you'd better do it like this:
Code: Select all
const size_t STACK_SIZE = 1024;
unsigned char stack[STACK_SIZE];
asm mov sp, [stack+STACK_SIZE]
Re:What is the diff between CS and DS
Posted: Mon Aug 08, 2005 3:26 am
by AR
Or more accurately:
That is unless you want to set SP to zero/garbage.
Re:What is the diff between CS and DS
Posted: Mon Aug 08, 2005 5:13 am
by codemastersnake
what about ss si and other stack regs
Re:What is the diff between CS and DS
Posted: Mon Aug 08, 2005 5:19 am
by Solar
Codemaster Snake wrote:
what about ss si and other stack regs
Sounds like you should give the Intel manuals another go.
SS is a segment register, i.e. it should point at the segment base address (with the SP being interpreted as offset from SS). The only other "stack register" I know of is BP, which is by default considered to be based on SS too.
SI is the
string (source) index, and is interpreted as relative to the DS segment register. It's counterpart is DI (
destination index, usually interpreted as relative to the ES segment register.