0

When changing the value of a variable an error occurs invalid effective address.

mov bl, var
mov [bl], 'a'
mov al, [bl] <--- here
mov ah, 0x0E
int 0x10

var db 'H'

As I know al is 8-bit and bl is a pointer pointing to 8-bit memory size.
There is something wrong that occurred after assigning a new value to var, I don't know why?


Code after debugging:

mov bx, var
mov byte [var], 'a'
mov al, byte [bx]
mov ah, 0x0E
int 0x10

var db 'H'
Lion King
  • 32,851
  • 25
  • 81
  • 143
  • 2
    No, `bl` *is* an 8-bit register, and you're trying to use it as a pointer, but x86 doesn't support 8-bit address-size. (8-bit operand-size is fine, but pointers are 16 bits wide in real mode). You should be getting an error on `mov [bl], 'a'` as well, about ambiguous operand-size as well as invalid address-size. – Peter Cordes Oct 21 '21 at 02:21
  • 2
    Interestingly, NASM does let you `mov bl, var` to put the low 8 bits of the address into BL, maybe only warning about that if the address happens to be >= 0xff? But if you want to deref it, you should `mov bx, var` – Peter Cordes Oct 21 '21 at 02:27
  • @PeterCordes: Is my code correct now [My Code](https://i.ibb.co/qdcK8Zd/20211021-044034.png)? (It's working) – Lion King Oct 21 '21 at 02:42
  • Yeah, looks fine. You could of course just use `[var]` if you don't want to put the address into a register first, like a C compiler would (for 32-bit mode) if you wrote `var = 'a'` / `return var;` in a function. – Peter Cordes Oct 21 '21 at 02:56
  • @LionKing Do not post links to external paste sites please. Instead [edit] your post and add your new code. – fuz Oct 21 '21 at 08:39
  • 2
    @Peter Cordes: I found two NASM bug reports about specifying labels in byte-sized contexts: [1](https://bugzilla.nasm.us/show_bug.cgi?id=3392678) and especially [2](https://bugzilla.nasm.us/show_bug.cgi?id=3392655) with a reply by hpa, a NASM developer. – ecm Oct 21 '21 at 14:54

0 Answers0