Assembly - ambiguous opcode combination

Programming, for all ages and all languages.
Post Reply
Cjreek
Member
Member
Posts: 70
Joined: Thu May 28, 2009 2:41 pm
Location: Germany

Assembly - ambiguous opcode combination

Post 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
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: Assembly - ambiguous opcode combination

Post 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.
Cjreek
Member
Member
Posts: 70
Joined: Thu May 28, 2009 2:41 pm
Location: Germany

Re: Assembly - ambiguous opcode combination

Post 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?
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Assembly - ambiguous opcode combination

Post 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
Cjreek
Member
Member
Posts: 70
Joined: Thu May 28, 2009 2:41 pm
Location: Germany

Re: Assembly - ambiguous opcode combination

Post 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 :)
Post Reply