开发者

Operand size conflict in x86 Assembly?

I'm a novice programmer who is attempting assembly for the first time. Sorry in advance if this is an incredibly lame question.

I have a character stored in the EAX register, but I need to move it to my DL register. When I try: mov dl, eax I get an error C2443: oper开发者_如何学JAVAand size conflict. I know that the eax register is 32 bit while the dl is 8 bit... am I on to something?? How do I go about solving this.


What you want is probably:

movzx edx, al

This will copy al to dl and zero fill the rest of edx. This single instruction is equivalent these two instructions:

xor edx, edx 
mov dl, al


Try

xor edx,edx
mov dl, al

perhaps? The first instruction to zero out the 'un-neccessary' high order bits of edx (optional), then just move the low 8 from eax into edx.

As others have pointed out, movzx does this in one step. It's worth mentioning that along the same lines, if you had a signed value in al, you could use "movsx edx, al" to fill the high order bits of edx with a copy of the msb of al, thereby putting a signed 32 bit representation of al into edx.


If you just want to access the lower 8 bits of eax, then use al:

mov dl, al

You can access the lower 8 bits, 16 bits, or 32 bits of each general purpose register by changing the letters at the start or end. For register eax, using eax means use all 32 bits, ax is the lower 16 bits, and al is the lower 8 bits. The equivalent for ebx is ebx, bx and bl respectively, and so on.

Note that if you modify the lower 16 or 8 bits of a register, then the upper bits are unchanged. For instance, if you load all ones in eax, then load zero into al, then the lower 8 bits of eax will be zeroes, and the higher 24 bits will be ones.

mov eax, -1 ; eax is all ones
mov al, 0 ; higher 24 bits are ones, lower 8 bits are zeros
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜