56800E Core - 56F8023 Assembly div and impy.l question

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

56800E Core - 56F8023 Assembly div and impy.l question

916 Views
sandrom
Contributor III

Hello all,

I'm analyzing for exercise this assembly piece of code, but I can't understand what it means...

bfset #0x10,OMR
move.w Var1,B1
move.w #23165,Y1
impy.l B1,Y1,A
move.w Var2,Y0
asl A
bfclr #1,SR
rep #0x000010
div Y0,A
move.w A0,X:Var3
bfclr #0x10,OMR

there is fractional arithmetic (I think 23165 is FRAC16(root(2)/2)), but I'm not sure).

Also the rep+div instructions and the 16-bit to 32-bit and backward operations are quite hard to understand for me.

Somebody can explain me in details the maths operations behind this code? Even in C code, no problem.

The scope of this calculation should be about Ripple elimination/rescaling of stator voltage in ACIM vector control (SVM) driving, but I'm not sure.

Thanks a lot in advance

Sandro

Labels (1)
4 Replies

665 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Sandro,

Sorry for the delay. i think that var3=(0.7*var1)/var2.

Hope it can help you

BR

Xiangjun Rong

665 Views
sandrom
Contributor III

Hello Xiangjun,

don't worry, thanks to you for helping me.

I quite agree to you, just one question: do you think the "asl A" instruction is part of the divide operation?

Because, if we consider it as a stand-alone operation, it should be:

var3=(2*(0.7*var1))/var2

What do you think about it? Am I wrong?

Thanks a lot,

best regards,

Sandro

0 Kudos

665 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Sandro,

Regarding the assembly instruction "asl A", i think it is dependent on the var1 and var2 format, in other words, whether they are Frac16 format or integer format. The above code treats the var1 and var2 as Frac16 format. Because it use


5.3.3 Multiplication in DSP56800ERM.pdf which can be downloaded from the link:
https://www.nxp.com/docs/en/reference-manual/DSP56800ERM.pdf?fsrch=1&sr=1&pageNum=1 

5.3.3 Multiplication
The multiplication operation is not the same for integer and fractional arithmetic. The result of a fractional
multiplication differs from the result of an integer multiplication. The difference amounts to a 1-bit shift of
the final result, as illustrated in Figure 5-13. Any binary multiplication of two N-bit signed numbers gives
a signed result that is 2N – 1 bits in length. This (2N – 1)-bit result must then be properly placed in a field
of 2N bits to fit correctly into the on-chip registers. For correct fractional multiplication, an extra zero bit is
inserted in the LSB to give a 2N-bit result. For correct integer multiplication, an extra sign bit is inserted in
the MSB to give a 2N-bit result.
In conclusion,it should be var3=(0.7*var1)/var2. while var1, var2, var3 are Frac16 format.
Hope it can help you
BR
Xiangjun Rong

665 Views
sandrom
Contributor III

HXiangjun,

thanks a lot for the detailed explanation.

Very hard to understand but I'll try to :smileyhappy: two last question: so do you think there isn't vars declared as 32-bit? is the compiler that converts "automatically" the multiplication in 32-bit impy.L ?

Last one: the I can't figure out the carry reset instruction bfclr #1,SR, do I have to write it in my C code? Or the compiler do it for me? I ask it because var3=(0.7*var1)/var2 doesn't put any bfclr operation in my assembly.

Thanks againg Xiangjun,

your answers are very helpful

Sandro

0 Kudos