0

I'm trying to compare a value in the data segment (an item in an array) to the ASCII character value for a space (20h, stored in a register) using a cmp instruction in MASM.

The instruction i'm attempting to use is: cmp [ds:bp + si + 1],cx

My goal is for ds:bp to represent the offset of an array into the data segment, si to contain the offset of a row into the two-dimensional array, and 1 (or a constant) to represent the element's position in a row.

However, when moving to assemble my code in MASM, i get error A2032: invalid use of register

in my mind, I'm using a base register, an index register and a constant, so all the components of indirect addressing are present.

I'm not sure what's going wrong; please have mercy on me, I'm new.

Appreciate help.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 2
    IIRC, MASM syntax wants the `ds:` outside the square brackets, like `ds:[bp]`. That might be the problem. Note that if you used BX instead of BP, DS would already be the default segment. I assume BX is already in use for a different pointer in your code. Also note that `cx` is a 16-bit register, so you're doing a 2-byte compare. You might want `cmp byte ptr ds:[bp+si+1], ' '`. to use an immediate constant with a byte memory operand. – Peter Cordes Jun 30 '21 at 03:00
  • Thank you, i've tried your first suggestion of ds: outside brackets, but i haven't tried the byte comparison suggestion, I'll implement that now and report back – CompSciStudent Jun 30 '21 at 03:05
  • Thank you Peter! Altering my implementation to ```cmp byte ptr DS:[BP + SI + 1],20h``` fixed the problem. It was only the two solutions together that worked. – CompSciStudent Jun 30 '21 at 03:10

0 Answers0