6

I tried to assemble a file with NASM, but it pointed to this line in the file:

mov al, byte ptr es:[bx]

saying:

error: comma, colon or end of line expected

I found a page on this site saying that NASM doesn't like the word "ptr" and it would be happy if I wrote:

mov al, byte es:[bx]

instead. So I took out the word "ptr" and NASM is still not happy. Here is what NASM gives me when I leave out the word "ptr":

warning: register size specification ignored

and:

error: invalid combination of opcode and operands

It's a catch 22! NASM is angry whether or not I put in the word "ptr". Can anybody help me with this?

Community
  • 1
  • 1
Isaac D. Cohen
  • 797
  • 2
  • 10
  • 26
  • 1
    I don't use NASM but try: `mov al, [es:bx]` or `mov al, byte [es:bx]` ... also it's been a while but es:bx may not be a valid x86 address, try to use di, `es:[di]` or `[es:di]` ... – Guy Sirton Jan 26 '14 at 03:02
  • Why isn't es:bx a valid address and es:di is? I can set bx to whatever I want and I can set di to whatever I want. – Isaac D. Cohen Jan 26 '14 at 03:33
  • 1
    It's not about what you can set- it's about what the processor can execute... I think it is valid though, try the alternate syntax I suggested and see if that works. – Guy Sirton Jan 26 '14 at 03:53
  • 1
    `es:bx` should be a valid combination, but as @GuySirton mentioned, the segment override should be placed inside the brackets (i.e. `mov al, byte [es:bx]`) – Michael Jan 26 '14 at 11:52
  • I have some more lines like this one in my code and some of them use ds:cx instead. When I assemble my code, NASM says "error: invalid effective address". Do you thing es:bx is invalid and ds:cx is valid? – Isaac D. Cohen Jan 26 '14 at 21:35
  • 1
    `cx` is not a valid base/index for addressing in 16-bit code. Refer to table 2.1 in section 2.1.5 of Intel's Software Developer's Manual Vol 2. – Michael Jan 27 '14 at 10:03

1 Answers1

5

I got it! NASM is happy if I write:

mov al,byte [es:bx]

like Guy Sirton said. If I leave out the word "byte" from the instruction, here is what would happen. If the instruction is one like this:

mov al, [es:bx]

where NASM can see that I want to move one byte, since I'm storing it in al, it won't complain. But, if the instruction is one like this:

mov [es:bx],0xff

where NASM can't see how much memory I want to store 0xff in, it will give you such an error:

error: operation size not specified

It's important to know, especially if you are using this tutorial, that NASM won't except the regular way.

Isaac D. Cohen
  • 797
  • 2
  • 10
  • 26