Home > other >  Cannot move a register to a register of a different size
Cannot move a register to a register of a different size

Time:09-20

When I write this:

mov cx,dh
mov dx,dl

It makes an error:

invalid combination of opcode and operands

I'm a beginner at assembly language so I need help!

CodePudding user response:

mov cx,dh

The error message you get for mov cx, dh means that the size of the CX destination register (16 bits) is different from the size of the DH source register (8 bits). For most instructions, operands must be the same size.

There are several ways to copy DH in CX.

   unsigned              signed
   --------              ------

1) movzx cx, dh       1) movsx cx, dh       ; 386 

                      2) mov   ch, dh       ; 186 
                         sar   cx, 8

2) mov   cl, dh       3) mov   al, dh       ; 8086 
   mov   ch, 0           cbw
                         mov   cx, ax

3) xor   cx, cx       4) mov   ch, dh
   mov   cl, dh          mov   cl, 8
                         sar   cx, cl

4) mov   al, 1        5) mov   al, 1
   mul   dh              imul  dh
   mov   cx, ax          mov   cx, ax

There are several ways to copy DL in DX.

   unsigned              signed
   --------              ------

1) movzx dx, dl       1) movsx dx, dl       ; 386 

                      2) mov   dh, dl       ; 186 
                         sar   dx, 8

2) mov   dh, 0        3) mov   al, dl       ; 8086 
                         cbw
                         mov   dx, ax

3) mov   al, 1        4) mov   dh, dl
   mul   dl              mov   cl, 8
   mov   dx, ax          sar   dx, cl

                      5) mov   al, 1
                         imul  dl
                         mov   dx, ax

Choose wise and stick with the simple ones!

  • Related