Page 1 of 1

Bad idea to modify DS register?

Posted: Mon Jun 03, 2013 1:04 pm
by computertrick
When you first set the DS register is it a bad idea to change it again to access offset's lower than the DS register.

I understand you can do something like this

Code: Select all

mov al, [gs:bx]
But I would prefer to use the SI register for certain routines. So basically lets say I have code which I make a call to and this code needs to access out of the boundaries of the DS register. Would it be a bad idea to do something like this?

Code: Select all

push ds
mov ax, 0x00
mov ds, ax
mov si, 0x00
....
pop ds
....
ret
So SI is pointing to the first byte in memory? is doing it like this bad I read some where that its not advised to change the DS register as it could cause some problems

Re: Bad idea to modify DS register?

Posted: Mon Jun 03, 2013 1:17 pm
by AJ
Hi,

What's the context? Looking at your code, you are probably in real mode using pure assembly. If so, then changing DS is perfectly valid, as long as you are aware of its value and you don't trash the stack or use BIOS interrupts where ds:si has a given meaning.

Cheers,
Adam

Re: Bad idea to modify DS register?

Posted: Wed Jun 05, 2013 1:11 am
by BMW
Also, a faster way to set a register to 0:

Code: Select all

xor si, si

Re: Bad idea to modify DS register?

Posted: Wed Jun 05, 2013 2:40 am
by iansjack
You should be aware that xor has side effects that mov 0 doesn't. The two instructions are not equivalent.

Re: Bad idea to modify DS register?

Posted: Wed Jun 05, 2013 2:42 am
by qw
computertrick wrote:When you first set the DS register is it a bad idea to change it again to access offset's lower than the DS register.
In real mode: physical address = segment address * 16 + offset. It was a good idea in the 80's I think.