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
What is the diff between CS and DS
Re:What is the diff between CS and DS
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.
The stack in realmode is in the SS segment, stack pointer is SP.
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
Re:What is the diff between CS and DS
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];
------
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
A segment in Real Mode is limited to 64k, so that's the maximum size of your stack segment.
Every good solution is obvious once you've found it.
Re:What is the diff between CS and DS
The stack grows downwards so you'd better do it like this:Codemaster Snake wrote: --------
unsigned char _STACK[1024]; //1KB... can I asign any value...
asm mov sp, [_STACK];
------
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
Or more accurately:That is unless you want to set SP to zero/garbage.
Code: Select all
mov sp, stack+STACK_SIZE
Re:What is the diff between CS and DS
Sounds like you should give the Intel manuals another go.Codemaster Snake wrote: what about ss si and other stack regs
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.
Every good solution is obvious once you've found it.