1

Here, I'm trying to move the variable X (which is an 8-bit variable) into the register bx (which is a 16-bit register). How can I move the value of X into the register bx in this case?

.686p
.model flat,stdcall
.stack 2048

.data
X byte 5
ExitProcess proto, exitcode:dword
.code

start:
invoke  ExitProcess, 0

mov bx, X; 1>p4.asm(13): error A2022: instruction operands must be the same size

end start ;what does the end statement do?
Anderson Green
  • 30,230
  • 67
  • 195
  • 328
  • 1
    Possible duplicate of [Cannot move 8 bit address to 16 bit register](http://stackoverflow.com/questions/33959446/cannot-move-8-bit-address-to-16-bit-register) – Peter Cordes Nov 27 '15 at 15:05

2 Answers2

5

In addition to Rahul's answer, if you also need to zero out bh and are working on anything 80386 or newer (as indicated by the .686p) is:

movzx bx, X

Of if you are using X as a signed value and needs to sign-extend bx:

movsx bx, X
DocMax
  • 12,094
  • 7
  • 44
  • 44
  • The directive `.686p` satisfies the requirements. – Aki Suihkonen Mar 21 '13 at 06:24
  • I suspected that, but wanted to guard against anyone treating the directive as boilerplate. (To be fair, I probably haven't written 16-bit code in 20 years, so the assumption seems pretty safe anyway.) – DocMax Mar 21 '13 at 06:28
3

The low 8-bits of BX are addressable as BL.

So, all you need to do is: mov bl, X

Rahul Banerjee
  • 2,343
  • 15
  • 16