0

I'm writing a boot sector code which contains the statements below:

xor cx, cx                      ;clear CX
cmp [cx], 'B'

I receive the error thrown by NASM:

error: operation size not specified


I modify the code like this:

cmp byte [cx], 'B'

However I receive another error:

error: invalid effective address


I'm searching on the error but I don't get to know why that is thrown

Megidd
  • 7,089
  • 6
  • 65
  • 142
  • 1
    Only a limited selection of registers can be used there. – Ignacio Vazquez-Abrams Oct 21 '17 at 10:14
  • 1
    16-bit addresses can only use limited registers. `[BX|BP] + [DI|SI]`, omit either base or index. Since you're zeroing `cx`, you could simply use `cmp byte [0], 'B'` – Peter Cordes Oct 21 '17 at 10:14
  • 2
    http://www.ic.unicamp.br/~celio/mc404s2-03/addr_modes/intel_addr.html – Ped7g Oct 21 '17 at 10:18
  • @PeterCordes `cx` register would be a counter in a loop. My other registers are filled by other things right now. Well, I think I might have to modify my code a whole lot – Megidd Oct 21 '17 at 10:19
  • 1
    Been searching for some nice duplicate with *"in x86-16 you have only these addressing modes available ..."*, but actually I didn't find one (only 32/64 bit ones). I give up, that external link was the best I found in one 32/64 answer. OP: also `bp, si, di` used? All of them? What are you doing? :-o :D – Ped7g Oct 21 '17 at 10:27
  • @user3405291: use si, di, or bx as your loop counter, then, and use cx instead of one of those. The `loop` instruction is only useful for code-size reasons; [it's not fast](https://stackoverflow.com/questions/35742570/why-is-the-loop-instruction-slow-couldnt-intel-have-implemented-it-efficiently), so other than that CX is mostly only special for shift counts (in CL). – Peter Cordes Oct 21 '17 at 11:28
  • @Ped7g: https://stackoverflow.com/questions/20786631/assembly-si-cx-impossible-combination-of-address-sizes has an answer that links the diagram on Wikipedia: https://en.wikipedia.org/wiki/X86#Addressing_modes. – Peter Cordes Oct 21 '17 at 11:29
  • 2
    @Ped7g: Actually, another one of SO's "related" links already had an answer that lists the full table of possibilities. I retitled it and linked wikipedia: https://stackoverflow.com/questions/12474010/nasm-x86-16-bit-addressing-modes – Peter Cordes Oct 21 '17 at 11:33

0 Answers0