Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

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

assembly - Move 32bit register into a 8 bit register

Im trying to move edx into al but i get this error

lib/io/print.asm:50: error: invalid combination of opcode and operands

this is the code

mov edx, 0x41
mov al, edx

thanks in advance

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

The problem is the second line:

mov al, edx

The edx register is 32-bits, but al is 8-bit, so you can't directly move one into the other. If you want to move the low 8 bits of edx into dl, do this:

mov al, dl

Or perhaps you want to move all of edx into eax, like this:

mov eax, edx

The difference is the first option leaves the high 24 bits of eax unchanged, while the second option sets them to the same as the corresponding bits of edx.

If you don't care about the high 24 bits, e.g., because you aren't going to use them, or because you know they are zero in either case, the second option may be slightly faster because it breaks the dependency on the previous value of eax, so it can execute as soon as edx is ready, regardless of what happened to eax before.

movzx eax, dl

MOVZX has the same benefit of avoiding a false-dependency on the AL destination, while only taking one byte from EDX and zero-extending it. The byte you want is in AL.

If you want a different byte of the source EDX, you can move and shift, or movzx eax, dh.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...