Page 1 of 1

Assembly - ambiguous opcode combination

Posted: Wed Oct 01, 2014 8:15 am
by Cjreek
Hi,

I hope I'm not too annoying with those assembly opcode questions :mrgreen:

NASM translates

Code: Select all

pop cs       --> 0x0F
add al, ah   -->      0x00 0xE0
verr ax      --> 0x0F 0x00 0xE0
to:
0x0F 0x00 0xE0 0x0F 0x00 0xE0
So how does the cpu know what to do?
NASM at least doesn't know because if you disassemble the binary above with ndisasm it prints:
;00000000 0F00E0 verr ax
;00000003 0F00E0 verr ax

Re: Assembly - ambiguous opcode combination

Posted: Wed Oct 01, 2014 8:23 am
by Octocontrabass
Cjreek wrote:

Code: Select all

pop cs       --> 0x0F
Which CPU is capable of executing that opcode as "pop cs"?

Find the answer to that question, and you'll see why it's not ambiguous.

Re: Assembly - ambiguous opcode combination

Posted: Wed Oct 01, 2014 8:29 am
by Cjreek
@Octocontrabass: I don't know. NASM translates pop CS straight to 0x0F. And I didn't find any other opcode for "pop cs".

That's why I made this thread.

Edit: Okay wikipedia writes:
POP CS (opcode 0x0F) works only on 8086/8088. Later CPUs use 0x0F as a prefix for newer instructions.
So there's just no "pop cs" instruction on x86 CPUs since 8086/8088?

Re: Assembly - ambiguous opcode combination

Posted: Wed Oct 01, 2014 8:37 am
by JAAman
there isn't any such instruction as "pop cs" that is why you didn't find it...

think carefully about what "pop cs" would do... its not something you would ever want to do...

therefore, when Intel wanted to increase the number of instructions, they needed an instruction to indicate an expanded instruction (like an escape sequence for instructions) they used that code, because "pop cs" doesn't mean anything and can't do anything other than cause the computer to crash strangely

seriously, you should be looking in the Intel manuals volume 2B, appendix A has all that information

Re: Assembly - ambiguous opcode combination

Posted: Wed Oct 01, 2014 8:47 am
by Cjreek
You're right. pop cs will most likely kill your computer. Except if you know exactly what you're doing :mrgreen:

I just wondered why there was no pop cs listed and I tried it in NASM and got 0x0F which confused me because of
0x0F being the prefix for 2-byte instructions and then ambiguous opcode combinations could occur.

I'm not at my dev. computer so I didn't want to download the intel manual right now.
Even if I've had the manual finding this information without exactly knowing where this information may be probably would have taken me a long time so I decided to ask here ;)

But in general you're right with pointing at the intel manuals :)