Addressing the adding situation
xania.org·1w·
⚙️Systems Programming
Preview
Report Post

Written by me, proof-read by an LLM. Details at end.

Yesterday we saw how compilers zero registers efficiently. Today let’s look at something a tiny bit less trivial (though not by much): adding two integers. What do you think a simple x86 function to add two ints1 would look like? An add, right? Let’s take a look!

Probably not what you were thinking, right? x86 is unusual in mostly having a maximum of two operands per instruction2. There’s no add instruction to add edi to esi, putting the result in eax. On an ARM machine this would be a simple add r0, r0, r1 or similar, as ARM has a separate destination operand. On x86, things like add are not result = lhs + rhs but lhs += rhs. This can be a li…

Similar Posts

Loading similar posts...