Author Topic: Why doesn't CMOVE work as expected?  (Read 12735 times)

Offline ben321

  • Full Member
  • **
  • Posts: 185
Why doesn't CMOVE work as expected?
« on: March 27, 2015, 07:14:42 AM »
I'm trying to conditionally set a certain variable called MemSeg, based on what key a user presses, for my experimental graphics program.
Code: [Select]
cmp byte al,0x30
cmove word [MemSeg],0xA000
cmp byte al,0x31
cmove word [MemSeg],0xB000
cmp byte al,0x32
cmove word [MemSeg],0xB800

But upon compiling, I get these errors. Why? Isn't the CMOVxx set of commands just like MOV, except for the fact that they are conditional based on the previous CMP statement?
Quote
a.asm:106: error: invalid combination of opcode and operands
a.asm:108: error: invalid combination of opcode and operands
a.asm:110: error: invalid combination of opcode and operands

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Why doesn't CMOVE work as expected?
« Reply #1 on: March 27, 2015, 08:31:40 AM »
Looks like the first operand to CMOVcc has to be a register.

(0xB000 ? Are you working in a museum? :) )

Best,
Frank


Offline ben321

  • Full Member
  • **
  • Posts: 185
Re: Why doesn't CMOVE work as expected?
« Reply #2 on: March 27, 2015, 09:01:03 AM »
Looks like the first operand to CMOVcc has to be a register.

(0xB000 ? Are you working in a museum? :) )

Best,
Frank

Code: [Select]
cmp byte al,0x30
cmove word dx,0xA000
cmp byte al,0x31
cmove word dx,0xB000
cmp byte al,0x32
cmove word dx,0xB800

Still gives the same error. Do BOTH operands have to be registers? Does CMOVcc mnemonics exist only for register-to-register transfers? If so, this could get a bit tricky.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Why doesn't CMOVE work as expected?
« Reply #3 on: March 27, 2015, 10:18:32 AM »
Register or memory, for the second operand - no immediates.

http://home.myfairpoint.net/fbkotler/nasmdocc.html#section-A.4.23

That's the old instruction set reference from the old Nasm Manual. Better to go straight to the manufacturers, but I'm used to this one. :)

Best,
Frank