1

I'm supposed to set both OF and ZF flag but I must use one of these: ADD, SUB, MUL or DIV but just once. I can use everything else and it can generate other flags too, I know how to do just ZF or just OF and I do understand the theory but I just can't seem to generate them both in this exercise.

Any help is appreciated, thanks!

EDIT: Solved

Simona
  • 349
  • 2
  • 8
  • 3
    So what two numbers and what operation can you perform on them that would result in a zero and an overflow? This isn't as hard as you think. There's probably more than one solution. Remember: a CPU word is a finite number of bits (which is why OF exists). – lurker Mar 13 '17 at 20:45
  • Click "edit" under your question and paste the code to set "just ZF or just OF". – Jose Manuel Abarca Rodríguez Mar 13 '17 at 20:46
  • Is this an X-Y question? Those flags are tested after operations which affect them, by branch instructions. What is the point of contriving them? Usually (x86) the only flags you explicitly set are `DF` and `CF` because they affect subsequent instructions. (Also some processors have IRQ control flag). – Weather Vane Mar 13 '17 at 20:59
  • @WeatherVane it's just an assignment to trigger both of them this way.. – Simona Mar 13 '17 at 21:04
  • @lurker Yep, that's what I've been trying to figure out but no luck – Simona Mar 13 '17 at 21:05
  • 2
    Try `mov ax, 0x8000` `add ax, 0x8000` . In this case both the signs are negative but when executed the sign of the result will be positive (result being 0x0000). In this case it should overflow and be zero. The carry flag should also be set of course. – Michael Petch Mar 13 '17 at 21:48
  • @MichaelPetch thank you! :) – Simona Mar 13 '17 at 21:52
  • @lurker : that won't overflow but it will set the carry. You'll need two values that have the *same* sign bit and when added together yield an opposite sign. In this case to get zero you'll need two such values that also equal 0. – Michael Petch Mar 13 '17 at 22:00
  • I know I had seen another SO answer that had a table that would help. Managed to find it in this answer: http://stackoverflow.com/a/8982549/3857942 . The question isn't really a duplicate but the answer is useful. – Michael Petch Mar 13 '17 at 22:03

1 Answers1

0

Why not do this:

 mov ax, 0x8000
 add ax, 0x8000

This will trigger ZF since AX will now be zero. This will also trigger OF since we have overflowed the maximum 16 bit value of ax.

David Hoelzer
  • 15,862
  • 4
  • 48
  • 67