0 item/s in cart
Usually the programs for the dsPIC devices are written in some of the higher programming languages. However, sometimes it is required that a section of the code is written in the assembler. This need is particularly emphasized for the processes involving complex processing. The optimization is possible in some of the higher programming languages, but it is most efficient when using the assembler, assuming that the architecture of the dsPIC30F devices is known. In these cases the core of the algorithm (most demanding part of the program) is programmed using the assembler. The basic problem when using the assembler instruction set is data memory access, which could be done in several ways. Each of these has its merits and defficiencies. It is thus very important to know the addressing modes and use them correctly while writing a program.Each assembler instruction can be divided into two parts. The first part of an instruction is the operation which is carried out (like mov, add, etc.) and the second is the operand(s). The operand is a value undergoing the operation. E.g. the instruction DEC W0, W1 carries out the operation of decrementing, defined by DEC, and the operands are the values in the registers W0 and W1. For the family of dsPIC30F devices there are four addressing modes:
MOV 0x0900, W0.This defines the operation of moving MOV (MOVe) while the operands are the value at the adrress 0x0900 in the data memory and the value kept in the register W0. The contents of the data memory at location 0x0900 and the register W0 before and after this instruction are shown in Fig. 8-5.
ADD W0, W1, W2The consequence of this instruction will be taking the values from the registers W0 and W1, adding them, and saving the result in the register W2. Here there are three operands: the values of W0, W1, and W2. The third operand will be overwritten by the result of adding of the first two. The values of the registers W0, W1, and W2 before and after the instruction are shown in Fig.8-6.
MOV [W1], W3The consequence of this instruction is that the value in the memory pointed by the register W1 will be written in the register W2. The register values and memory locations before and after the instruction are shown in Fig. 8-7.
MOV $0900, W1 MOV #0, W2 REPEAT #5 MOV W2, [W1++]This example writes zeros to six sequential locations in the memory. The instruction REPEAT has the consequence that the subsequent operation is executed the specified number of times plus one, i.e. MOV W2, [W1++] will be executed six times.
|AT START||BEFORE THE LOOP||AFTER THE LOOP|
|W1 0xFFFF||W1 0x0900||W1 0x0900|
|W2 0xFFFF||W2 0x0000||W2 0x0000|
|0x0900 0xFFFF||0x0900 0xFFFF||0x0900 0x0000|
|0x0902 0xFFFF||0x0902 0xFFFF||0x0902 0x0000|
|0x0904 0xFFFF||0x0904 0xFFFF||0x0904 0x0000|
|0x0906 0xFFFF||0x0906 0xFFFF||0x0906 0x0000|
|0x0908 0xFFFF||0x0908 0xFFFF||0x0908 0x0000|
|0x090A 0xFFFF||0x090A 0xFFFF||0x090A 0x0000|
MOV [W1+W2], W3The address of the first operand is calculated by adding the values in the registers W1 and W2. The obtained value is the address in the memory where the operand is saved (the value which should be written into the register W3). The location with this address is read and the value written into the register W3. All this is performed in one instruction. Of all described modes of indirect register addressing (without register modification, with register modification, and shift register), the majority of instructions supports only indirect rgeister addressing without modification. The instruction MOV supports all the modes. DSP instruction set supports only post-increment and post-decrement mode, but the value by which a register is modified can be selected. The increment/decrement value can, in this case, be ±2, ±4, and ±6. For more details concerning DSP instructions, see Chapter 11.
|OPERAND||INSTRUCTION WHERE IT IS USED||RANGE|
|#bit4||BCLR, BSET, BTG, BTSC, BTSS, BTST, BTST.C, BTST.Z, BTSTS, BTSTSS.C, BTSTS.Z||0 ... 15|
|#lit1||PWRSAV||0 ... 1|
|#lit4||ASR, LSR, SL||0 ... 15|
|#lit5||ADD, ADDC, AND, CP, CPB, IOR, MUL.SU, MUL.UU, SUB, SUBB, SUBBR, SUBR, XOR||0 ... 31|
|#lit8||MOV.B||0 ... 255|
|#lit10||ADD, ADDC, AND, CP, CPB, IOR, RETLW, SUB, SUBB, XOR||0 ... 1023|
|#lit14||DISI, DO, LNK, REPEAT||0 ... 16383|
|#lit16||MOV||0 ... 65535|
|#Slit4||ADD, LAC, SAC, SAC.R||-8 ... +7|
|#Slit6||SFTAC||-32768 .. +32767|
|#Slit10||MOV||-512 ... +512|
ADD W1, #4, W2In the example the value of the register W1 is added 4 and the result is written into W2. For the second operand the literal addressing is used. From the table it can be seen that with the instruction ADD one can use constants within the range 0...31.