0

The instruction set reference says that the ZF is undefined for the imul instruction. So what happens to the ZF if I multiply a value in a register by an immediate value of 0x0?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
mkg190
  • 5
  • 1
  • Related: [How is the sign flag calculated with the imul instruction?](https://stackoverflow.com/q/29901622) - SF is undefined as well – Peter Cordes Aug 17 '22 at 19:57

1 Answers1

2

Undefined means that result can be anything and none of the values matter anything.

Andrey
  • 59,039
  • 12
  • 119
  • 163
  • So if the result of an imul operation is zero, the ZF could be 0? – mkg190 Apr 22 '14 at 18:30
  • @mkg190 it could be 0, 666 or 0xDEADBEEF. – Andrey Apr 22 '14 at 21:48
  • @Andrey: ZF is only a single bit, it's always either zero or 1. This is assembly language, not C undefined behaviour. `setz al` will produce 0 or 1. You just don't know which. `jz` will either go to the target or fall through, not jump somewhere else. (And yes, on at least some CPUs, for example Skylake, it actually will set ZF=0 even when both halves of the result are zero. Same if it's non-zero) – Peter Cordes Feb 09 '22 at 18:48