Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

assembly - What does ADD r/m8* , imm8 mean in the Intel x86 docs, how do I invoke the `REX + 80 /0 ib` rule?

Finally starting to get the hang of Volume 2 of the Intel docs. However, one piece is confusing me currently. Looking at the ADD instruction, there are these two different opcodes which have the same operand signature:

opcode           call                  description
80 /0 ib         ADD r/m8, imm8        Add imm8 to r/m8
REX + 80 /0 ib   ADD r/m8*, imm8       Add sign-extended imm8 to r/m64

I understand the first one, but not the second one. If we did this:

add cl, 1

We get:

80 c1 01

The first one is like this:

80 /0 ib

That makes sense.

The second one, with the REX prefix, would look like this:

0b01000000 80 /0 ib

...from my understanding, with byte value 01000000 (0100 being the magic first 4 bits of REX). 01000000 is 40 in hex.

I would expect to pass in an r8 as per the instruction call signature, such as ah, like this:

add ah, 1

And get out:

40 80 /0 01

Where /0 you lookup in the table for the register, which would be c4 for AH, so you'd have:

40 80 c4 01

But I don't, in this case NASM gives me:

80 c4 01

Why doesn't it have the REX prefix???

I see there is the asterisk * in ADD r/m8*, imm8, which says:

* In 64-bit mode, r/m8 can not be encoded to access the following byte registers if a REX prefix is used: AH, BH, CH, DH.

So that tells me I can't use AH, I think. But if I try some other 8-bit register (AX, BX, CX, DX, SP, BP, SI, DI, CS, SS, ES, DS, IP), like:

add sp, 1

I get:

66 83 c4 01

Which corresponds to:

<prefix> 83 /0 ib

I don't have any idea yet why they added that 66 prefix, but that is probably a separate question. If you know, feel free to answer that too.

Trying other registers gives me similar results.

What am I doing wrong. How do I generate something that invokes the rule REX + 80 /0 ib?

question from:https://stackoverflow.com/questions/65947932/what-does-add-r-m8-imm8-mean-in-the-intel-x86-docs-how-do-i-invoke-the-rex

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...