ss, ds and es as same values. what would happen ?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
extremecoder
Member
Member
Posts: 59
Joined: Tue May 23, 2006 11:00 pm

ss, ds and es as same values. what would happen ?

Post 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 ...
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: ss, ds and es as same values. what would happen ?

Post 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.
nekton
Posts: 4
Joined: Sat May 02, 2009 10:03 am

Re: ss, ds and es as same values. what would happen ?

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: ss, ds and es as same values. what would happen ?

Post 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.
Post Reply