Remix.run Logo
pansa2 3 hours ago

> Using `lea` […] is useful if both of the operands are still needed later on in other calculations (as it leaves them unchanged)

As well as making it possible to preserve the values of both operands, it’s also occasionally useful to use `lea` instead of `add` because it preserves the CPU flags.

andrepd 2 hours ago | parent [-]

Funny to see a comment on HN raising this exact point, when just ~2 hours ago I was writing inline asm that used `lea` precisely to preserve the carry flag before a jump table! :)

MYEUHD an hour ago | parent [-]

I'm curious, what are you working on that requires writing inline assembly?

veltas an hour ago | parent | next [-]

I'm not them but whenever I've used it it's been for arch specific features like adding a debug breakpoint, synchronization, using system registers, etc.

Never for performance. If I wanted to hand optimise code I'd be more likely to use SIMD intrinsics, play with C until the compiler does the right thing, or write the entire function in a separate asm file for better highlighting and easier handing of state at ABI boundary rather than mid-function like the carry flags mentioned above.

vardump 35 minutes ago | parent | prev [-]

Might be an interpreter or an emulator. That’s where you often want to preserve registers or flags and have jump tables.