Steinar H. Gunderson: Decompilation patterns, part 18: Signed division

As promised, the last one (for now?), and this one blew my mind the first time I saw it: var_v0 = sp4014; if ((s32) sp4014 < 0) { var_v0 = sp4014 + 0x7FF; } temp_s1 = 0x800 – (sp4014 – (((s32) var_v0 >> 0xB) << 0xB)); There's actually two things going on here. First, the compiler is faking a signed division using shifting (which rounds down) as a building block: If the value is negative, then you add a bias…
Quelle: Originalartikel öffnen
