Page 1 of 1
ss, ds and es as same values. what would happen ?
Posted: Sun May 03, 2009 12:12 am
by extremecoder
I am setting up the value for ds, ss and es as same values like this:
mov ax, 0x1000
mov ds, ax
mov es, ax
mov ss, ax
what would happen to data sections ? this I am doing in stage1 and stage2 loaders ... sometimes excess allocation of bytes using resb erases some part of memory and also loads other stages if it is not intended to be loaded ...
Re: ss, ds and es as same values. what would happen ?
Posted: Sun May 03, 2009 12:27 am
by pcmattman
Do you know anything about real mode addressing? Read the Intel Manuals and you'll get a better picture of where in RAM you're accessing when you use a segment:offset pair.
Re: ss, ds and es as same values. what would happen ?
Posted: Sun May 03, 2009 3:42 am
by nekton
There is no problem in having DS and SS point the same segment. For example like this: DS:SI = 1000:0000, SS:SP = 1000:fffe. Stack grows towards lower addresses, you just have to make sure data and stack don't overlap.
I had one situation where the C code below didn't work without DS and SS being set to the same values. fn1 reserves the buffer from the stack with something like SP=SP-16, fn1 used the correct address for buffer[0], but fn2 used incorrect one.
Code: Select all
void fn1() {
char buffer[16];
buffer[0] = 'a';
fn2(buffer);
if (buffer[0] == 'b')
...
}
void fn2(char *buffer) {
buffer[0] = 'b';
}
Yes, you should read more about absolute addresses and segment:offset addresses.
Re: ss, ds and es as same values. what would happen ?
Posted: Sun May 03, 2009 4:16 am
by JamesM
nekton wrote:
I had one situation where the C code below didn't work without DS and SS being set to the same values. fn1 reserves the buffer from the stack with something like SP=SP-16, fn1 used the correct address for buffer[0], but fn2 used incorrect one.
Most C compilers assume that DS == SS. Changing that will break its generated code.