REVE1 Logs
Bitwise OR sets each result bit to 1 where either input has a 1 — so 0x69 | 0x55 = 0x7D; it's the go-to operator for turning flag bits on.
0x69 | 0x55 → 0x7D
01101001 (0x69)
| 01010101 (0x55)
──────────
01111101 (0x7D)
Common uses:
1. Set specific bits:
// Set the writ...
Q Why did computer architects choose two's complement over other signed number representations?
It lets one adder handle both signed and unsigned numbers, and it has a single zero — unlike sign-magnitude and one's complement.
Alternative representations considered:
Method
-5 (4-bit)
Problem
Sign-magnitude
1101 (1=neg, 101=5)
Need separate add/subtract circuits
One'...
Q How does signed (two's complement) addition handle overflow?
The bits are added exactly as for unsigned, but overflow shows up as an impossible sign change: pos + pos → negative, or neg + neg → positive.
Positive overflow: Two positive numbers sum to negative
Negative overflow: Two negative numbers sum to positive
Example (4-bit, range -8...
Q What does a & b do in C (bitwise AND)? What is 0x69 & 0x55 (01101001 & 01010101)?
Bitwise AND sets each result bit to 1 only where both inputs have a 1 — so 0x69 & 0x55 = 0x41.
01101001 (0x69)
& 01010101 (0x55)
──────────
01000001 (0x41)
Common uses:
1. Extract/mask specific bits:
// Get lowest 8 bits
int lowByte = value & 0xFF;
// Get bit 3 (0 or 1)
i...
Q Why does the compiler convert while and for loops into do-while form internally?
Because do-while — "run the body, then conditionally jump back" — is the only loop shape the hardware directly provides; everything else is built on top of it.
Hardware offers straight-line execution plus conditional branches. The do-while pattern maps onto that with zero overhea...
Q How does structure member ordering affect the struct's size, and how can you minimize padding?
Poor ordering scatters padding between members; ordering members from largest/strictest alignment to smallest packs them tightly and shrinks the struct.
* Member ordering changes padding: declare fields in decreasing alignment order to shrink the struct. *
Because each member mu...
Q What is the difference between caller-saved and callee-saved registers, and when do you use each?
Caller-saved: the called function is free to clobber them, so the caller must save anything it still needs. Callee-saved: the function must preserve them, restoring their original values before returning.
* Caller-saved may be clobbered by the callee (temporaries); callee-saved...
Q What do cqto (and the related cdq/cltd) do, and why does signed division need them?
They sign-extend the value in %rax/%eax into the full %rdx:%rax/%edx:%eax pair, building the high half a signed idiv requires.
* cqto sign-extends rax into rdx to build the 128-bit rdx:rax dividend; unsigned div zeroes rdx with xor instead. *
x86 signed division (idivq) divides...
Q What are the big-picture takeaways for how C is translated into assembly?
Assembly has no high-level constructs at all — every loop, branch, and data structure dissolves into compares, jumps, and fixed memory offsets that the compiler computes ahead of time.
The whole topic reduces to three lessons about what disappears when C becomes machine code:
Con...
Q How does GDB's x (examine) command format work for reading memory, such as a jump table?
x/NFU address — examine N items, in Format (x=hex, d=dec, i=instruction, s=string…), of Unit size (b/h/w/g = 1/2/4/8 bytes) — starting at address.
GDB's x is the Swiss-army knife for inspecting raw memory while reverse-engineering. The count, format, and unit are bundled into one...