Move 32bit register into a 8 bit register

醉酒当歌 提交于 2020-08-20 12:41:12

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/57531562/move-32bit-register-into-a-8-bit-register

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!