News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Error A2070 - puzzling

Started by carlottagp, October 02, 2008, 10:47:44 AM

Previous topic - Next topic

carlottagp

I am trying to get data from a file into my program, which of course involves
interpreting ASCII codes.

The line in my code which is problematic is:

sub [BX], 30h

I get an A2070 error for this line, referring to
"invalid instruction operands."  (Some earlier lines,
without errors, deal with letters A through F.)

But this line looks like a simple subtraction to me.

Any advice appreciated!

Michael

sinsi

Too ambiguous - you can subtract from a byte in memory as well as a word (dword, qword). Use a size override
sub BYTE PTR [BX],'0'

Light travels faster than sound, that's why some people seem bright until you hear them.

carlottagp

Thank you for the suggestion, although I don't fully understand it, since
in a previous line I had set BX to the offset of a buffer.  Presumably you
are suggesting that I insert your line ahead of mine.

Meanwhile, experimenting, I have copied [BX] to AL, and then subtracted
30h from AL; no error messages after this change.

Thanks again,

Michael

Neil

What sinsi means is replace your line:-

                             sub [BX], 30h

with his line:-           sub BYTE PTR [BX],'0' 

There is no need to move it into al, all you have to do as sinsi says is use a size override i.e.

                             BYTE PTR   or  WORD PTR   etc.

otherwise the assembler doesn't know what you are subtracting from.

MichaelW

Michael,

Given this instruction:

sub [BX], 30h

ML has no way of knowing what the size of the destination operand is, and this information is essential to correctly encode the instruction, because the destination operand could be a BYTE, a WORD, or a DWORD. For example, here are the three possible forms:

    sub BYTE PTR [bx], 30h
    sub WORD PTR [bx], 30h
    sub DWORD PTR [bx], 30h


And here is the assembled machine code (in hex) for each instruction, followed by a disassembly of the instruction:

802F30    sub BYTE PTR [bx], 30h
832F30    sub WORD PTR [bx], 30h
66832F30  sub DWORD PTR [bx], 30h


As you can see each form has a different encoding. If instead of a constant the source operand were a register, ML would assume that the size of the destination operand matched the size of the source operand:

    sub [bx], al
    sub [bx], ax
    sub [bx], eax


2807      sub BYTE PTR [bx], al
2907      sub WORD PTR [bx], ax
662907    sub DWORD PTR [bx], eax

eschew obfuscation