reko icon indicating copy to clipboard operation
reko copied to clipboard

Detect functions returning sequences of registers

Open uxmal opened this issue 3 years ago • 0 comments

It's common to return register pairs or n-tuples from procedures when the return value exceeds the register size. For instance, in MS-DOS binaries, long pointers are returned in the dx:ax register pair. Reko today handles long input parameters passably, but functions returning register tuples inevitably end up looking like this:

word16 myfunc(word16 & dxOut) {
    dx_ax = ds->dw0044;
    dxOut = dx_ax >> 16; // or worse, SLICE(dx_ax, word16, 16)
    return (word16) dx_ax;
}

There is still a place for out parameters, but in this case it should be more appropriate to generate:

word32 myfunc() {
    return ds->dw0044;
}

uxmal avatar Jan 17 '22 11:01 uxmal