-1

i'm doing a quiz on assembly and the question was :
enter image description here

we need to give the value of eax after the program and the answer was : 0x80000000 and it says that when 0x7FFFFFFF goes to 0x80000000, OF goes to 1 but i don't understand why. This value seems random to me (pretty sure it isn't thought)

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
hey
  • 118
  • 9
  • Related: [about assembly CF(Carry) and OF(Overflow) flag](https://stackoverflow.com/q/791991) / [x86 Assembly: INC and DEC instruction and overflow flag](https://stackoverflow.com/q/3925528) explain some about what signed-overflow is 2's complement integer math. **See also http://teaching.idallen.com/dat2343/10f/notes/040_overflow.txt** – Peter Cordes May 18 '22 at 21:22

1 Answers1

1
        movl $0, %ecx
Boucle: addl $1, %ecx
        jno  Boucle

The ECX register can hold the signed numbers that range from 0x80000000 to 0x7FFFFFFF. When the addl instruction raised ECX to 0x80000000, this range was exceeded and the CPU signals this via its overflow flag.
With this flag SET, the loop was interrupted. It could only continu while the OF was not set.

we need to give the value of eax after the program

If this isn't a typo, then the answer would be impossible to give...

Sep Roland
  • 33,889
  • 7
  • 43
  • 76