2

when I try

mov [ax], bx

I get the following error: invalid effective address same goes for mov [al], bl or something similar.

if I try

mov [bx], ax

it works. So what is so special about the lower bytes of ebx, and how can I accomplish something along the lines of mov [al], bl or just swap the contents of the two bytes in bx,ax,etc. ?

Thanks in advance for anything helpful :)

Seki
  • 11,135
  • 7
  • 46
  • 70
Claas
  • 23
  • 3
  • Possible duplicate of [invalid effective address calculation!](http://stackoverflow.com/questions/2809141/invalid-effective-address-calculation) Short answer: not all registers can be used that way. – Frédéric Hamidi Jan 08 '13 at 16:02
  • Linux programs will be running in 32 or 64-bit (unless you do something really weird). Use 32-bit or 64-bit addressing, like `[eax]` is fine. – Peter Cordes Oct 24 '22 at 10:54

1 Answers1

4

The use of [bx] is called the "register indirect addressing mode". in 16-bit mode the following registers can be used in this manner: bx, bp, si and di.

For more information, see The Register Indirect Addressing Modes.

how can I accomplish something along the lines of mov [al], bl

This doesn't quite make sense because it would use the 8-bit value of al as an address, and addresses in this case are 16-bit. If you are just trying to move the value of bl into al, then the square brackets are unnecessary:

mov al, bl
NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • In 32-bit and 64-bit assembly, though, [it *is* possible](http://ref.x86asm.net/coder.html#modrm_byte_32). –  Jan 08 '13 at 16:04
  • 2
    @Tinctorius `mov [al],bl` is **not** a valid instruction in 32-bit or 64-bit x86 assembly any more than in 16-bit x86 assembly. However, `mov [eax],bl` is valid 32-bit instruction and `mov [rax],bl` is a valid x86-64 instruction. – nrz Jan 08 '13 at 16:08
  • Very true :) If that's really what OP wants, `movzx ax, al` (or `movzx eax, al`, or `movzx rax, al`) followed by a swap between `ax` and `bx`, and then `mov [bx], al`. –  Jan 08 '13 at 16:13
  • I'm confused by the reference to Linux. Will Masm run in Linux? Japheth's JWASM should, though... – Frank Kotler Jan 08 '13 at 20:06