1

I came through the following statement while going through a binary search program code

l1: mov si,low_ cmp si,high_ 

Why do we need to store low_ in si and then compare with high_ ? Can't we directly write cmp low_,high_

3
  • 5
    Only up to one memory operand is supported by most x86 instructions. Commented Aug 4, 2021 at 16:48
  • Did you try it? Your assembler would have told you "too many memory operands". Commented Aug 5, 2021 at 0:14
  • Try it first, then ask here.. Commented Aug 27, 2021 at 22:20

1 Answer 1

3

You cannot write cmp low_, high_.

For such questions, always refer to the official instruction description, e.g. at https://www.felixcloutier.com/x86/cmp. Note that cmp has forms cmp r/m16, r16, for which the first operand can be either register or memory, and the second must be a register; as well as cmp r16, r/m16 which is the reverse. But there is nothing like cmp r/m16, r/m16 or cmp m16, m16. So cmp low_, high_ would be attempting to assemble an instruction which does not exist, and your assembler will reject it.

This is the case for most x86 arithmetic instructions: one of the operands may be a memory reference, but not both. To operate on two values from memory, you must load one of them into a register first, as this code does.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.