Window conflict size in x86 Assembly?

I am a beginner programmer who is trying to build 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 error message C2443: operand conflict. I know that the eax register is 32 bits, while dl is 8 bits ... am I on something? How do I solve this.

+7
assembly x86
source share
3 answers

You probably want:

movzx edx, al 

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

 xor edx, edx mov dl, al 
+11
source share

Try

 xor edx,edx mov dl, al 

may be? The first instruction is to nullify the β€œunnecessary” high order bits of edx (optional), and then simply move the low 8 from eax to edx.

As others have pointed out, movzx does this in one step. It is worth noting that on the same lines, if you have a signed value in al, you can use "movsx edx, al" to fill the high-order bit edx with a copy of msb al, thereby putting the signed 32-bit al representation in edx.

+6
source share

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

 mov dl, al 

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

Please note that if you change the lower 16 or 8 bits of the register, the upper bits do not change. For example, if you load everything in eax, then load zero in al, then the lower 8 bits of eax will be zeros, 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 
+3
source share

All Articles