1
org 100h

mov ah, 9
mov dx, str1
mov byte [str1+2], [char]
int 21h

mov ah, 4Ch
int 21h

str1 db 'String$'
char db "o"

Why does NASM give me this error message:

Error on line 5: Invalid combination of opcode and operands

mov byte [str1+2], [char] 

in this line I'm trying to move the byte stored on *char to the address *str1+2.

phuclv
  • 37,963
  • 15
  • 156
  • 475
user1091856
  • 3,032
  • 6
  • 31
  • 42
  • [What x86 instructions take two (or more) memory operands?](https://stackoverflow.com/q/52573554/995714), [Why cannot do `mov [eax], [ebx]`](https://stackoverflow.com/q/54482505/995714), [Assembly: MOVing between two memory addresses](https://stackoverflow.com/q/1299077/995714), [Why isn't movl from memory to memory allowed?](https://stackoverflow.com/q/33794169/995714) – phuclv Feb 12 '19 at 01:29

1 Answers1

7

Intel architecture processors generally can't transfer data from memory to memory in one instruction. You need to write something like:

mov byte al, [char]
mov byte [str1+2], al
Mat
  • 202,337
  • 40
  • 393
  • 406
Marek Rocki
  • 126
  • 1
  • 1
    There is a execption, `movs` does transfer from memory to memory in one instruction, but it doesn't allow you to choose the addressing modes freely. – Gunther Piez Dec 23 '11 at 09:47
  • This answer needs to have a tag added to it: *"How to append/edit/modify byte arrays"*. I have a buffer (`1 + 2;`) which is not NULL terminated. When I get to the `;`, I wanted to append a `0x00` byte. This finally got me over that. Awesome! – IAbstract Apr 21 '15 at 14:32