0

I get this error. "Instruction operands must be the same size

I believe it has something to do with the size of the variable "choice"

.data
    choice BYTE ?

mov choice, eax     ; error on this line
    call Crlf
    ret
DisplayMenu ENDP

DisplayOpr PROC USES edx
    mov eax, choice     ; error on this line

What do I need to do to fix this error?

lurker
  • 56,987
  • 9
  • 69
  • 103
Colby W
  • 1
  • 2
  • 1
    You allocate one byte of storage for `choice` but then try to store 4 bytes into it. What do you want to achieve? – fuz Apr 09 '19 at 19:00
  • i believe I need to store 4 bytes – Colby W Apr 09 '19 at 19:03
  • If you want to store 4 bytes into `choice`, then you need to make `choice` a `dword` variable. – fuz Apr 09 '19 at 19:04
  • When i replace BYTE with DWORD I get a linker error. Code LINK2005. How would i work around that? – Colby W Apr 09 '19 at 19:07
  • Please post the full linker error, not just its code. – fuz Apr 09 '19 at 19:30
  • Basically a duplicate of [Using variable with register: error A2022: instruction operands must be the same size](https://stackoverflow.com/q/16270280). Or for this special case, also [Why can't I move directly a byte to a 64 bit register?](https://stackoverflow.com/q/22621340) re: movzx – Peter Cordes Jan 30 '22 at 01:58

1 Answers1

0

The register eax is 32-bits long, whereas choice is only a single BYTE (i.e. 8 bits).

You can change choice to be 32-bits long by declaring it as such:

choice DD 0AABBCCDDh

Alternatively, if choice is supposed to be a single byte long, you can use the 8-bit partial register al, which refers to the least significant byte of the register EAX:

mov al, choice
Govind Parmar
  • 20,656
  • 7
  • 53
  • 85
  • Usually to load a byte you want `movzx eax, byte ptr [choice]`, unless you specifically want to merge with whatever was in the upper part of EAX/RAX. – Peter Cordes Jan 30 '22 at 02:00