DSP Built-in Routines
mikroBasic PRO for dsPIC30/33 and PIC24 includes a collection of DSP Built-in Routines. This section describes the programmer interface to DSP instructions.
Bare in mind that most optimal DSP code can only be achieved by direct asm coding. We strongly discourage usage of these built-in routines for performance critical applications.
For the sake of compatibility each of these sub functions can be called by its alias formed by replacing 'DSP
' name part with '__builtin
'.
However, these aliases will not be visible in code assistant.

A
' and 'B
'.
Library Routines
- DSP_ADDAB
- DSP_ADD
- DSP_CLR
- DSP_CLR_prefetch
- DSP_ED
- DSP_EDAC
- DSP_LAC
- DSP_MAC
- DSP_MOVSAC
- DSP_MPY
- DSP_MPYN
- DSP_MSC
- DSP_SAC
- DSP_SACR
- DSP_SFTAC
- DSP_SUBAB
DSP_ADDAB
Prototype |
sub function DSP_ADDAB(const acc_a as integer, const acc_b as integer) as integer |
---|---|
Description |
Add accumulators Assembler Operator / Machine Instruction : |
Parameters |
Both arguments can be ommited. |
Returns |
Returns the addition result to an accumulator. |
Requires |
Nothing. |
Example |
A = DSP_ADDAB() |
Notes |
An error message will be displayed if the result is not an accumulator register. |
DSP_ADD
Prototype |
sub function DSP_ADD(const acc as integer, dim value as integer, const shift as integer) as integer |
---|---|
Description |
Add value to the accumulator specified by result with a shift specified by literal shift. Assembler Operator / Machine Instruction : |
Parameters |
|
Returns |
Returns the shifted addition result to an accumulator. |
Requires |
Nothing. |
Example |
dim value as integer A = DSP_ADD(A, value, 0) |
Notes |
An error message will be displayed if :
|
DSP_CLR
Prototype |
sub function DSP_CLR() as integer |
---|---|
Description |
Clear the specified accumulator. Assembler Operator / Machine Instruction : |
Parameters |
None. |
Returns |
Returns the cleared value result to an accumulator. |
Requires |
Nothing. |
Example |
A = DSP_CLR() |
Notes |
An error message will be displayed if the result is not an accumulator register. |
DSP_CLR_prefetch
Prototype |
sub function DSP_CLR_prefetch(dim xptr as ^^integer, dim xval as ^integer, const xincr as integer, dim yptr as ^^integer, dim yval as ^integer, const yincr as integer, dim AWB as ^integer) as integer |
---|---|
Description |
Clear an accumulator and prefetch data ready for a future MAC operation.
If AWB is non null, the other accumulator will be written back into the referenced variable. Assembler Operator / Machine Instruction : |
Parameters |
|
Returns |
Returns the cleared value result to an accumulator. |
Requires |
Nothing. |
Example |
dim x_memory_buffer as integer[256] xdata dim y_memory_buffer as integer[256] ydata dim xmemory as ^integer dim ymemory as ^integer dim awb as integer dim xVal, yVal as integer xmemory = x_memory_buffer ymemory = y_memory_buffer A = DSP_CLR_prefetch(@xmemory, @xVal, 2, @ymemory, @yVal, 2, @awb) ' After this instruction: '- result will be cleared, '- xVal will contain x_memory_buffer[0], '- yVal will contain y_memory_buffer[0], '- xmemory and ymemory will be incremented by 2, ready for the next MAC operation |
Notes |
An error message will be displayed if :
The compiler may need to spill W13 to ensure that it is available for the write-back. It may be recommended to users that the register be claimed for this purpose. |
DSP_ED
Prototype |
sub function DSP_ED(dim sqr as integer, dim xptr as ^^integer, const xincr as integer yptr as ^^integer, const yincr as integer, dim distance as ^integer) as integer |
---|---|
Description |
Squares Assembler Operator / Machine Instruction : |
Parameters |
|
Returns |
Returns the squared result to an accumulator. |
Requires |
Nothing. |
Example |
dim xmemory, ymemory as ^integer dim distance as integer A = DSP_ED(distance, @xmemory, 2, @ymemory, 2, @distance) |
Notes |
An error message will be displayed if :
|
DSP_EDAC
Prototype |
sub function DSP_EDAC(const acc as integer, dim sqr as integer, dim xptr as ^^integer, const xincr as integer, dim yptr as ^^integer, const yincr as integer, dim distance as ^integer) as integer |
---|---|
Description |
Squares Assembler Operator / Machine Instruction : |
Parameters |
|
Returns |
Returns the computed result to specified accumulator. |
Requires |
Nothing. |
Example |
dim xmemory, ymemory as ^integer dim distance as integer A = DSP_EDAC(A, distance, @xmemory, 2, @ymemory, 2, @distance) |
Notes |
An error message will be displayed if :
|
DSP_LAC
Prototype |
sub function DSP_LAC(dim value as integer, dim shift as integer) as integer |
---|---|
Description |
Shifts Assembler Operator / Machine Instruction : |
Parameters |
|
Returns |
Returns the shifted result to an accumulator. |
Requires |
Nothing. |
Example |
dim value as integer A = DSP_LAC(value,3) |
Notes |
An error message will be displayed if :
|
DSP_MAC
Prototype |
sub function DSP_MAC(const acc as integer, dim a as integer, dim b as integer, dim xptr as ^^integer, dim xval as ^integer, const xincr as integer, dim yptr as ^^integer, dim yval as ^integer, const yincr as integer, dim AWB as ^integer) as integer |
---|---|
Description |
Computes
If Assembler Operator / Machine Instruction : |
Parameters |
|
Returns |
Returns the computed result to an accumulator. |
Requires |
Nothing. |
Example |
dim xmemory as ^integer dim umemory as ^integer dim xVal, yVal as integer A = DSP_MAC(A, xVal, yVal, @xmemory, @xVal, 2, @ymemory, @yVal, 2, 0) |
Notes |
An error message will be displayed if :
|
DSP_MOVSAC
Prototype |
sub function DSP_MOVSAC(dim xptr as ^^integer, dim xval as ^integer, const xincr as integer, dim yptr as ^^integer, dim yval as ^integer, const yincr as integer, dim AWB as ^integer, const AWB_acc as integer) as integer |
---|---|
Description |
Computes nothing, but prefetches data ready for a future MAC operation.
If Assembler Operator / Machine Instruction : |
Parameters |
|
Returns |
Nothing, just prefetches data. |
Requires |
Nothing. |
Example |
dim xmemory as ^integer; dim ymemory as ^integer; dim xVal, yVal as integer DSP_MOVSAC(@xmemory, @xVal, 2, @ymemory, @yVal, 2, 0, A) |
Notes |
An error message will be displayed if :
|
DSP_MPY
Prototype |
sub function DSP_MPY(dim a as integer, dim b as integer, dim xptr as ^^integer, dim xval as ^integer, const xincr as integer, dim yptr as ^^integer, dim yval as ^integer, const yincr as integer) as integer |
---|---|
Description |
Computes
Assembler Operator / Machine Instruction : |
Parameters |
|
Returns |
Returns the computed result to an accumulator. |
Requires |
Nothing. |
Example |
dim xmemory as ^integer dim ymemory as ^integer dim xVal, yVal as integer A = DSP_MPY(xVal, yVal, @xmemory, @xVal, 2, @ymemory, @yVal, 2) |
Notes |
An error message will be displayed if :
|
DSP_MPYN
Prototype |
sub function DSP_MPYN(dim a as integer, dim b as integer, dim xptr as ^^integer, dim xval as ^integer, const xincr as integer, dim yptr as ^^integer, dim yval as ^integer, const yincr as integer) as integer |
---|---|
Description |
Computes
Assembler Operator / Machine Instruction : |
Parameters |
|
Returns |
Returns the addition result to an accumulator. |
Requires |
Nothing. |
Example |
dim xmemory as ^integer dim ymemory as ^integer dim xVal, yVal as integer A = DSP_MPYN(xVal, yVal, @xmemory, @xVal, 2, @ymemory, @yVal, 2) |
Notes |
An error message will be displayed if :
|
DSP_MSC
Prototype |
sub function DSP_MSC(const acc as integer, dim a as integer, dim b as integer, dim xptr as ^^integer, dim xval as ^integer, const xincr as integer, dim yptr as ^^integer, dim yval as ^integer, const yincr as integer, dim AWB as ^integer) as integer |
---|---|
Description |
Computes
If Assembler Operator / Machine Instruction : |
Parameters |
|
Returns |
Returns the computed result to an accumulator. |
Requires |
Nothing. |
Example |
dim xmemory as ^integer dim ymemory as ^integer dim xVal, yVal as integer A = DSP_MSC(A, xVal, yVal, @xmemory, @xVal, 2, @ymemory, @yVal, 2, 0) |
Notes |
An error message will be displayed if :
|
DSP_SAC
Prototype |
int DSP_SAC(const acc as integer, const shift as integer) as integer |
---|---|
Description |
Shifts accumulator by Assembler Operator / Machine Instruction : |
Parameters |
|
Returns |
Returns the shifted accumulator value. |
Requires |
Nothing. |
Example |
dim res as integer res = DSP_SAC(A, 3) |
Notes |
An error message will be displayed if :
|
DSP_SACR
Prototype |
int DSP_SACR(const acc as integer, const shift as integer) |
---|---|
Description |
Shifts value by Assembler Operator / Machine Instruction : |
Parameters |
|
Returns |
Returns the shifted accumulator value. |
Requires |
Nothing. |
Example |
dim res as integer res = DSP_SACR(A, 3) |
Notes |
An error message will be displayed if :
|
DSP_SFTAC
Prototype |
sub function DSP_SFTAC(const acc as integer, const shift as integer) as integer |
---|---|
Description |
Shifts accumulator by Assembler Operator / Machine Instruction : |
Parameters |
|
Returns |
Returns the shifted accumulator value. |
Requires |
Nothing. |
Example |
dim i as integer A = DSP_SFTAC(A, i) |
Notes |
An error message will be displayed if :
|
DSP_SUBAB
Prototype |
sub function DSP_SUBAB(const acc_a as integer, const acc_b as integer) as integer |
---|---|
Description |
Subtracts accumulators Assembler Operator / Machine Instruction : |
Parameters |
Both arguments can be ommited. |
Returns |
Returns the subtraction result to an accumulator. |
Requires |
Nothing. |
Example |
A = DSP_SUBAB() |
Notes |
An error message will be displayed if the result is not an accumulator register. |
What do you think about this topic ? Send us feedback!