News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Sign extended long value

Started by Seb, July 03, 2005, 02:09:17 AM

Previous topic - Next topic

Seb

Hello!

I am having a problem here. I've translated the following C macro a C function which uses inline Assembly, but the result is not exactly what I want. The Assembly code generates a 0.5-1 second long static/white noise sometimes while playing an audio file, but the C code works fine:


#define SIGN_EXTENDED32(val, bits) ((val << (32 - bits)) >> (32 - bits))


Note: A few of you may also think "why optimize for a macro or a small piece of code like that?", well, let me put it this way: I want my code to be as optimized as possible.

For the Assembly version, I've tried several opcodes, but all of them result in exactly the same behavior (static/white noise in the audio file, at exactly the same playing position too), and I am out of clues. I've tried cdq, rcl/rcr and rol/ror:


long SIGN_EXTENDED32(long val)
{
__asm {
mov eax, DWORD PTR [val]
rol eax, 15
ror eax, 15
}
}


The weird thing is that it doesn't generate static/noise for random parts in the audio file, it happens on exactly the same position for all methods (except for the C method of course).

Is there anything wrong with my code, or is there any easier/faster way to do this?

Regards,
Sebastian Andersson

Edit: Incorrect words in sentence.

Seb

Nevermind, I managed to solve it myself. :U sal/sar did the job.