tags:

views:

194

answers:

2

I've been looking around online a little bit at assembly tutorials and have been flipping through Art of Assembly as well.

I keep getting hung up on one thing when changing segment registers though.

I see code like:

mov ax, cs
mov ds, ax
mov es, ax

Why can't I just compress this to:

mov ds, cs
mov es, cs

Is the first way faster since its using the accumulator register? But that wouldn't seem intuitive since cs and ds are segment registers. Or is there some restriction that I'm unaware of?

I'm using nasm by the way.

+7  A: 

You can't mov segment register to segment register -- there's no instruction for it.

Dave
When I first read your response I didn't believe you, but in NASM's documentation, sure enough, no mov reg_dseg, reg_cseg instruction.
samoz
This is not the reason, it is the result.
anon
What? I don't understand what you mean Neil.
samoz
Ask yourself WHY the x86 does not have those particular instructions.
anon
@Neil - Actually this *is* the answer to "Why do the book authors not mov ds, cs?" and even more specifically his question "is there some restriction that I'm unaware of?" However, the next natural question would be "wtf, why not?" so your answer is helpful there.
dss539
+1  A: 

There is only so much room in a processor for the microcode for all its instructions. So one general instruction is often preferred over several special purpose ones for rarely uused operations lake changing segment registers. Also, for some processors the number of instructions is absolutely limited by the architecture - for example, the original 8080 processor was limited to 256 instructions as they all had to have the op code encoded in a single byte.

anon
+1 for explaining the reason behind the reason
dss539