This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ASM programming a new DP macro



Hi Folks,

I am working on a F2802x using the DPLib. I would like to add another small macro of my own but have exceedingly little experience with ASM... while I am looking at the Instruction set reference guide and understanding the explanation of commands I do not have the knowledge of "how things should be done" in ASM, maybe someone can help?

I am trying only to make a simple signal ramping macro. It has two inputs - the signal (Signal) and the current ramp step value (Ref) and one output (Out). The macro simply needs to multiply the two inputs, which are in IQ24 format and then output the result.

I think I have got as far as getting the multiplication of the two 32 bit numbers but now need to round the result and shift it right by 24. I think maybe I have the rounding addition OK but the right-shift presents me a problem as the now 64-bit value is of course split over two registers... how to solve this and shift right, with the result being the correct 32-bit value??

i.e. In psuedo-code the operations are:

temp = Signal * Ref;
temp += 2^24;
temp >>= 24;

So far the business logic of the  assembly look as follows:

RAMP_GEN	.macro n
;=============================
; set up address pointers
 MOVW	DP, #_RAMP_GEN_Ref:n:
 MOVL 	XAR0, @_RAMP_GEN_Ref:n:		; net pointer to Ref (XAR0)
 MOVW	DP,#_RAMP_GEN_Signal:n:
 MOVL    XAR1, @_CNTL_2P2Z_Signal:n:	; net pointer to Signal (XAR1)
 MOVW	DP,#_RAMP_GEN_DBUFF:n:
 MOVL	XAR3, #_RAMP_GEN_DBUFF:n:	; pointer to the DBUFF array (used internally by the module)
 MOVW	DP,#_RAMP_GEN_Out:n:
 MOVL    XAR2, @_RAMP_GEN_Out:n:	; net pointer to Out (XAR2)

 ZAPA
; compute ramp output
 MOV 	XT, *XAR0		; Move the Ref value into the multiplicand register
 IMPYL 	ACC, XT *XAR1		; ACC = low 32-bits of (Ref * Signal)
 QMPYL 	P, XT, *XAR1		; P = high 32-bits of (Ref * Signal)
 MOV 	*XAR3, #2		; Move 2 into the data buffer
 LSL 	*XAR3, #24		; Shift data buffer left 24 to get Q24 multiplier
 ADDL 	ACC, *XAR3		; Add Q24 multiplier to ACC to round up the multiplication result

; NEED TO DO THE RIGHT-SHIFT(24) HERE ON THE NUMBER CONSTITUTED BY P : ACC

 MOVL 	*XAR2, ACC		; Move low 32-bits from ACC to Out

.endm