Bad idea to modify DS register?

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
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Bad idea to modify DS register?

Post 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
1100110100010011
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Bad idea to modify DS register?

Post 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
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: Bad idea to modify DS register?

Post by BMW »

Also, a faster way to set a register to 0:

Code: Select all

xor si, si
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Bad idea to modify DS register?

Post by iansjack »

You should be aware that xor has side effects that mov 0 doesn't. The two instructions are not equivalent.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Bad idea to modify DS register?

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