Category: Low level programming
-
Swapping values of two variables with XOR
As programmers, we know that we can swap two variables by using a temporary variable. That’s fairly simple and intuitive: given two variables (x and y) that you want to swap, you store x in a temporary variable z, copy y to x, then finally copy z (the temporary) to y. But I learned recently…
-
Here’s some assembly instructions … now write the corresponding C code
A wide grin formed on my face, after successfully completing an exercise (from Computer Systems a Programmer’s perspective) that required me to write C code, based off a sequence of a six assembly instructions: void decode1(long *xp, long *yp, long *zp) { /* xp stored in %rdi, yp in %rsi, zp in %rdx) decode1: movq (%rdi),…