Monthly Archives: April 2006

Why does PUSHA also push the stack pointer?

This puzzle is actually a quite easy one – but when I asked it in a university course, it kept some people busy for some time to find out the answer, so I thought it might be a good idea to ask you nevertheless:

The 8086 “PUSHA” instruction saves the following registers on the stack:
AX, CX, DX, BX, SP, BP, SI, DI
In i386+ 32 bit mode, these registers are EAX etc., and in x86_64 64 bit mode, it is RAX etc., but all of them always also save the stack pointer.

Why do x86 CPUs do this? Isn’t it true that it makes no sense to save the stack pointer, as the stack pointer is needed to retrieve these values anyway?

In a few days, I’ll post some trivia on this topic…

Puzzle: PowerPC Flag Simulation on x86

This week’s puzzle is to copy the carry flag to the high bit of ah.  You may destroy any other register, the flags, and the other 24 bits of eax.  Shortest sequence wins.

For an optional very long description of what this is all about, click “Read the rest”.  You don’t need to read it to participate in the contest =)

Continue reading