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 ...
ss, ds and es as same values. what would happen ?
-
- Member
- Posts: 59
- Joined: Tue May 23, 2006 11:00 pm
-
- 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 ?
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 ?
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.
Yes, you should read more about absolute addresses and segment:offset addresses.
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';
}
Re: ss, ds and es as same values. what would happen ?
Most C compilers assume that DS == SS. Changing that will break its generated code.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.