0

I'm trying to write a function in assembly to perform a bubble sort. I'm passing a pointer to an array as a parameter and trying to operate upon it to sort the array. I need to compare two values within the array, but when I try to I get "error A2026:constant expected". The error appears in the following lines:

mov ecx, [arr + pos2 * 4]
cmp [arr + pos * 4], ecx

I am using x86 and MASM (Intel syntax).

SPFort
  • 53
  • 1
  • 10
  • 1
    It's not clear what syntax you are using. MASM uses Intel syntax. – Raymond Chen Apr 28 '18 at 21:06
  • This is not MASM Intel syntax. Still unclear. – zx485 Apr 28 '18 at 21:41
  • I guess I'm not quite sure what the correct syntax is. That could be my problem afterall. – SPFort Apr 28 '18 at 22:42
  • 1
    You can read the manual to see what the correct syntax is. oh look, you edited the question and changed the syntax. It's still wrong, but for a different reason. You need to read the manual to see what addressing modes are permitted. – Raymond Chen Apr 28 '18 at 22:51
  • I'm doing my best here, these are all things that I've seen on the internet/learned in class. I understand that I need to research things on my own and I am very willing to do that, I guess I just don't really know where to find this information. – SPFort Apr 28 '18 at 23:11
  • For this to work you will need to place the address of `pos2` into a register, and the address of `pos` in a register. Then you will have to use those registers in the addressing. Scaling doesn't operate on an address value it can only scale the value in a register. – Michael Petch Apr 28 '18 at 23:36
  • 2
    try `mov esi, offset pos2` `mov edi, offset pos` `mov ecx, [arr + esi * 4]` `cmp [arr + edi * 4], ecx` (_esi_ and _edi_ can be any of the available general purpose registers – Michael Petch Apr 29 '18 at 00:05
  • 1
    You have to use registers in addressing modes, not values in memory. `pos*4` is the problem. (You can use the base address of the array directly, though, as an assemble-time constant.) I think this is a duplicate of [Referencing the contents of a memory location. (x86 addressing modes)](//stackoverflow.com/q/34058101), but maybe there's a more specific Q&A about MASM syntax. – Peter Cordes Apr 29 '18 at 02:43

0 Answers0