简体   繁体   中英

Cannot move a register to a register

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!

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
                         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   ah, dh
   mov   cl, dh          mov   cl, 8
                         sar   ax, cl
                         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
                         sar   dx, 8

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

                      4) mov   dh, dl
                         mov   cl, 8
                         sar   dx, cl

Choose wise and stick with the simple ones!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM