Hi,

I'm a little confused about modulo operation but maybe there is a stupid simple answer that I don't see at the moment.

I use a ADSP-21469 programmed with VisualDSP++ 5.0 Update 10.1 in "C".

I tried to do a modulo operation but failed with a result of 0 all the time.

Following I've tested:

#define NUM_SAMPLES 0x10000

tempsize = TOC.Data[n].length % NUM_SAMPLES; ==> result is always 0

ASM-Code:

[08E4FE] r2=fext r2 by 0:0x6;

[08E4FF] r2=lshift r2 by 0xa;

but if I replace the NUM_SAMPLES by it's value:

tempsize = TOC.Data[n].length % 0x10000; ==> correct result

ASM-Code:

[08E4FE] r2=fext r2 by 0:0x10;

In my opinion the first code can not work correctly.

At another code location I've also used a modulo operation and the result was

[08D6A7] cjump ___uldiv(db)

giving me also the correct result (modulo value is 0x5A).

Any ideas?

Thanks

Christian

Hi Christian,

Looking at the screenshot, the problem is that NUM_SAMPLES is defined like this:

#define NUM_SAMPLES 64*1024

When the preprocessor expands this into the tempsize calculation, the result is this:

tempsize = TOC.Data[0].length % 64*1024;

The remainder operator and the multiply operator have the same precedence and associate left-to-right, so the compiler interprets it like this:

tempsize = (TOC.Data[0].length % 64)*1024;

Due to these sorts of surprises, it's generally a good idea to enclose macro definitions in parentheses:

#define NUM_SAMPLES (64*1024);

Regards,

Andy