Handling Arithmetic Right Shifts in ObjectPascal
In translating some DSP C++ code to ObjectPascal, I am seeing a quite a few ">>" operators on signed integers (the right operand always being 1 or 2). I know that on signed integers C++ performs an arithmetic right shift as opposed to a logical right shift in Pascal.
Currently I am substituting a 'div 2' or 'div 4' command for these ASR shifts. Is there a better, or more general, way to handle these?
Yes, assuming that the left operand is a 32-bit variable:
And if you want the general case for x>>N: