1

I learned in the class that we can use pointers in assembly with these brackets []. but in my program that dosent work and give me 'wrong parameters error'. will be very happy if you help me :)

cmp [cx], num
JNE LOOP1
inc count
jmp LOOP1

how you can see, i try count number of "num" in an array, and there is problem with the first line

zx485
  • 28,498
  • 28
  • 50
  • 59

2 Answers2

2

Simple answer: x86 assembly doesn't support two explicit memory operands in one instruction.

So your first instruction cmp [cx], num is invalid. Load one of the arguments into a register first, and then execute the comparison (for example, like this):

mov ax, num     ; preferably outside the loop
cmp [cx], ax
JNE LOOP1
inc count
jmp LOOP1

This should fix that problem.

[cx] isn't a valid 16-bit addressing mode either, so pick BX, SI or DI instead for iterating a pointer over the array.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
zx485
  • 28,498
  • 28
  • 50
  • 59
0

I get it, the problem was that I made cx a pointer, but the only bx, di and si can be pointers. so now my code looks like this :

mov bx, cx
cmp [bx], ax
JNE LOOP1
inc count
jmp LOOP1