Vous êtes sur la page 1sur 9

EEE 591 REAL TIME DSP LAB 3.

INTRODUCTION TO THE DSP56800E ASSEMBLY


By Ramsri Golla , Jidnyasa Babar

INTRODUCTION The DSP56800E is the newest of Freescales families of Digital Signal Controllers. Pure C, Hybrid, as well as Pure Assembly language codes can be loaded onto the DSP56858 this lab aims at introducing the set of instructions specific to the processor with the help of numerous examples. OBJECTIVE The objective of this lab is to introduce students to the DSP56800E assembly instruction Set and in the process understand the Assembler statement syntax and directives. Different addressing modes. Arithmetic operations. Branch and looping instructions

RESULT AND ANALYSIS Example : 3

Q. In what portion of the accumulators (i.e.: A0, A1 or A2) is the number loaded for each
instruction? Which instruction should be used to load accumulator A with decimal value 100000? Why?

A. The instruction MOVE.W #10, A loads decimal 10 into A1. This is because the
nstruction used pertains to a word. Now when the accumulator A has to be loaded with the decimal value of 100000, the instruction MOVE.L #100000, A has to be used. This is because the binary equivalent of decimal 100000 is greater than 16 bits.

Q. What is the difference between the output of MOVE.W A1, R1 and MOVEU.W
A1, R1?

A. Since MOVE.W A1, R1 is used with signed numbers and A contains decimal -10, on its
execution, 2s complement of 10 is stored with a sign extension of 1. Thus R1 now contains 0XFFFFF6. Now since MOVEU.W A1, R1 works with unsigned integers, R1 stores the 2s complement but with the sign extension of 0. Thus R1 now contains 0X00FFF6 Example 5:

Q. What will be the content of register X0 ? A. The contents of X0 are the contents present at the address 0000 which is 0XFF0A.
Example 8:

Q. Debug the code above and check the value of B after each iteration. What is wrong
in that code? What is the final result of A? What should it be? How are the bytes stored in memory?

A. The value of B after each iteration is


Iteration 1 Iteration 2 Iteration 3 Iteration 4 0x0000030000 0x0000050000 0x0000000000 0x0000000000

The problem with the code is that the final result should have been E , whereas it comes out to be 8. This is because MOVE.B is used to access which is a word pointer. As a result each time the increment operation is executed a new word is accessed and not the next byte.
The most significant 8- bits of the word store the first byte. The 2nd byte is then stored in the least significant 8-bits. The 3rd byte is then stored in the most significant and the 4th in the least significant 8 bits of the next word.

Q. Rewrite Example 8 using MOVE.BP; you may use the built-in assembler functions
described in Table 3. These functions are useful for converting a word address into a byte address (byte pointer)

A. The modification in the code is given as follows :


ORG X: X1 DCB 2,3,4,5

ORG P: MOVE.L #@lb(X1), R1 ;move word pointer to R1 MOVE.W #0, A ;clear A MOVE.W #0, B ;clear B DO #4,Loop ; start looping MOVE.BP X:(R1+0),B ;read byte and store in B ADD B, A ; Add A + B -> A ADDA #1, R1 ; increment R1 Loop: The modification ensures that each consecutive byte is accessed by converting the word address to the byte address. The final result of A is 0x00000E0000.

Example 9:

Q. In the CW menu select, View > Registers and check for A2, A1, A0, Y0, B2, B1, B0. Where
is the multiplication result located? By default, results are shown in hexadecimal; right click on the hexadecimal number and select View as Signed Decimal to change to decimal.

A.
A2 A1 A0 Y0 B2 B1 B0 0x00 1388 0000 0x0000FFFD 0x0F C568 0000 0 5000 0 -3 15 -15000 0

The multiplication result is stored in B1. Example 10:

Q. Check the accumulator B for the result, is overflow occurring? Usually, the result needs
to be stored back in memory and, in this case, the result will occupy two memory locations. This is not recommended for large algorithms. Can you think of a mechanism to prevent overflow using only 16-bit results.

A. The accumulator B contains 0X000001E848 which is decimal 125000.

Here since 2 16- bit numbers are being multiplied, an overflow will occur only if we attempt to store the 32-bit result as it will occupy 2 memory locations. To avoid the overflow we could use fractional multiplication and Q15 notation. Example 11:

Q. Check the values in B1, B0 and X0. What is the result of the multiplication? A.
B1 B0 X0 0x2000 0x0000 0x2000

The result of the multiplication is stored in X0. X0 contains decimal 8192 which is the Q15 equivalent of 0.25. Example 12 :

Q. Check again for the result in B1, B0 and X0. Is it the same as the one previously
obtained? Perform the following fractional multiplication using Example 12: is the result obtained in B and X0? Comment.
5 5 * 15 . What 15 2 2

A. B1, B0 and X0 contain the same values as before.


5 5 * 15 is performed using example 12, both B and X0 contain 0. This is because underflow 15 2 2 occurs. The product is so small that even after Q15 the values obtained is less than 1.
If Example 13:

Q. Measure the number of cycles and instruction count for the MAC operation. (Start measuring at
the instruction after the CLR A and upto and including the MAC instruction). Compare with the number of cycles and instruction count you obtained for doing a MAC operation in assembly in PART B of lab 2. (Note: Here you are performing the MAC three times, hence you must multiply the number of cycles and instruction count you obtained from lab2 by three)

A. PART A :
Machine cycles instruction count PART B : Machine cycles instruction count 7 6

591 303

Example 14:

Q. What is the content of accumulator A after code execution? A. The Accumulator A has 0X000A after the execution. This is the result of skipping the third
statement. Example 15:

Q. Is the BEQ condition satisfied? Continue executing the program and check the content of the
memory location TEST_VAR. Rather than initializing the TEST_VAR to 3 change it to be 5, execute the code again and check for the results. Can you think of another way to perform the same task in assembly? (Hint: use BNE instead of BEQ, refer to [1] page A-57) Write the following C program in assembly: If (x = = 3); {x ++;} Else {x--;}

A. The BEQcondition is satisfied. TEST_VAR contains 0004. When the TEST_VAR is changed to
5, the value of the TEST_VAR still contains 3. Another way using BNE command is given below: MOVE.W #3, X0 ; Move 3 to X0 MOVEU.W #TEST_VAR, R0 ; Get memory address into R0 SUB.W X:(R0), X0 ; Subtract 3 from TEST_VAR BNE Cont_code ; If the results are not zero goto Cont_code Increment: INC.W X:(R0) ; Increment variable TEST_VAR Cont_code: Nop Assembly equivalent of the C Program is: ; metrowerks sample code section rtlib org x: TEST_VAR DC 3 org p:

global Fmain SUBROUTINE "Fmain",Fmain,FmainEND-Fmain

; assembly level entry point Fmain: MOVE.W #3, X0 ; Move 3 to X0 MOVEU.W #TEST_VAR, R0 ; Get memory address into R0 SUB.W X:(R0), X0 ; Subtract 3 from TEST_VAR BEQ Increment ; If the results is zero goto ;Increment BRA Cont_code ; Empty Else, skip to label ;Cont_code Increment: INC.W X:(R0) ; Increment variable ;TEST_VAR BRA Cont_code_in ; Cont_code: DEC.W X:(R0) ; Cont_code_in: nop rts FmainEND: endsec end Example 18:

Q. Which method is more efficient? Compare instruction cycles for example 17 and 18. A. Looping performed using software instructions is slower compared to looping using hardware
registers Q . 17 (software looping ) Machine cycles 94 instruction count 34 Q.17 (Hardware registers for looping) Machine cycles 34 instruction count 12 Thus hardware looping is much more efficient than software looping.

Q. Difference between MOVE.W, MOVE.L, MOVE.B and MOVE.BP: A. MOVE.W: Move word using word pointers and word addresses.
MOVE.L: Move long word using word pointers.

MOVE.B : Move byte using word pointers and byte addresses . MOVE.BP Move byte using byte pointers and byte addresses.

Q. Difference between fractional and integer multiplication: A. Integer multiplications are performed using IMPY.L and IMPLYW. The inputs given are
two words or two bytes and the output is a long word or a word. It suffers from overflow problem. Fractional multiplication is performed using MPY. Here the values are represented in Q15 format. Overflow occurs only during additions of fractions but not during multiplications. However the problem of underflow occurs at times due to truncation of lower bits.

Q. Difference between software and hardware looping: A. Software looping used instructions like BEQ,BNE whereas hardware looping uses DO,
REP instructions. Software looping is conditioned looping whereas hardware looping is unconditional. Also hardware looping is faster and efficient than software looping.

Q. Difference between different addressing modes: A. Absolute Addressing : If the operand is located in memory, the address of the memory
location can be found within the instruction. Indirect Addressing: If the operand is located in memory, the address of the memory location can be found in the address generation unit (AGU) register. Immediate Addressing :Immediate addressing is used when the value to be loaded in the accumulator or internal register is provided in the operand itself. LAB EVALUATION:

Q. Describe any difficulties encountered while performing the lab? A. Understanding Move.BP and Move.B took us good amount of time while performing the
lab. AlsoQ15 format and its use was also difficult to comprehend initially.

Q. List any errors or unclear statements found in the lab manual. A. Q15format and its use could have been given in little more detail with explanation using
an example.

Q. Give suggestions in improving this lab.

A. We believe that the lab served its purpose well. Taking an example and explaining would
help to understand better at certain points. CONCLUSION

Q. Described what you learnt from the lab? A. The lab gave a very good introduction to different type of addressing modes, arithmetic
operations, branching/looping instructions, assembler statement syntax and derivatives. We understood the code flow and it helped us gain experience to think in compiler optimization coding which we werent previously unconcerned about. We understood the Q15 notation and how to avoid overflow in multiplication. We understood the importance of Move.BP and Move.B and their used in different scenarios.

Q. Indicate what you liked most and what you liked least. A. We completely liked the way lab experiments were designed. Understanding Q15
format, difference between hardware and software looping, efficiency of MAC instruction impressed us the most. We liked the lab completely so there is no such thing as liked the least. SUPPLEMENTAL (BONUS POINTS)

Q. Using Q15 format, write an assembly code that will perform the following operation: P
=Q*R + S, where Q = 0.25, R = 0.125 and S =0.5. The values of Q, R, and S should be read from data memory and the result written back to memory.

A.
sectionrtlib ORGX: X1DC 8192,4096 ; corresponding to Q=0.25 and R=0.125 org p:

globalFmain SUBROUTINE"Fmain",Fmain,FmainEND-Fmain ;assembly level entry point Fmain: MOVEU.W#X1,R0

CLRA MOVE.WX:(R0)+,Y0 MOVE.WX:(R0)+,A MPYA1,Y0,B CLRA MOVE.W#16384,A ADDB,A MOVE.WA,X:(R0) nop rts FmainEND: endsec end ; A contains S=0.5 ; Perform Q*R + S and store in A ; Result written Back into Memory ; do nothing ; Y0 contains Q=0.25 ; A contains R=0.125 ;16 x 16fractional multiply . B contains Q*R

Vous aimerez peut-être aussi