Clarskon
Clarskon

Reputation: 159

Single Instruction Alternates of code snippets

What'll be the single Instruction alternates of following code snippets. I have been trying for hours and can't really figure them out

  1. CMP EBX,EAX JNE X1 MOV EBX,ECX JMP X2 X1: MOV EAX,EBX X2
  2. PUSHF MOV BH,FFH CMP BL,0 JL X1 NOT BH X1: POPF
  3. BT AX,15 JC X1 AND EAX,0000FFFFH JMP X2 X1: OR EAX, FFFF0000H X2:
    Please provide an explanation too.
    Thanks

Upvotes: 0

Views: 77

Answers (1)

Jester
Jester

Reputation: 58792

  1. Looks like cmpxchg ebx, ecx. if (eax == ebx) ebx = ecx else eax = ebx
  2. That gives 0FFh in bh if bl is negative, or 00h otherwise. As such that's just sign extending, ie. movsx bx, bl
  3. That's basically the same, it's sign extending ax by testing the sign bit directly, ie. it is movsx eax, ax. But note this doesn't affect flags as opposed to the code snippet.

Upvotes: 3

Related Questions