Thursday, May 26, 2016

8051 Program - signed 16bit multiply Accumulate table

; subroutine MACD16
; 16-Bit x 16-Bit to 32-Bit Product signed Multiply-Accumulate
; with table data and data move.
; y(n) = x(n)*h0 + x(n-1)*h1 + x(n-2)*h2 + ......
; Note: Assumes shared program/data space. i.e. PSEN and RD are
; OR-ed together on the board.
; 2's Complement format
; input: B = No. of 16-bit data items in tables (max 63)
; DPTR --> New Input data (e.g. from ADC)
; DPTR+2 --> Base of Data Table (x)
; DPTR+128 --> Base of Multiplier Table (h)
; output: r7, r6, r5, r4 = 32-bit accumulated result
; calls: MUL16
; alters: acc, flags, Bits 21H & 22H
MACD16:anl PSW, #0E7H
mov r4, #0 ;Clear Accumulator
mov r5, #0
mov r6, #0
mov r7, #0
movx a, @DPTR
push acc ;Save XNEWL
inc DPTR
movx a, @DPTR
push acc ;Save XNEWH
inc DPTR
Macd1:movx a, @DPTR ;Get x(n)L
mov r0, a
push acc ;Save x(n)L
mov a, #80H
movc a, @a+DPTR ;Get h(n)L
mov r2, a
inc DPTR
movx a, @DPTR ;Get x(n)H
mov r1, a
push acc ;Save x(n)H
mov a, #80H
movc a, @a+DPTR ;Get h(n)H
mov r3, a
lcall MUL16+3 ;Do Multiply...
mov A, r4 ;then Accumulate..
add A, r0
mov r4, A
mov A, r5
addc A, r1
mov r5, A
mov A, r6
addc A, r2
mov r6, A
mov A, r7
addc A, r3
mov r7, A
pop 01 ;Now move x data
pop 00
pop 03
pop 02
push 00
push 01
mov a, r3 ;Move up x(n)H
movx @DPTR, a
mov a, #0FFH
add a, dpl
mov dpl, a
mov a, #0FFH
addc a, dph
mov dph, a
mov a, r2 ;Move up x(n)L
movx @DPTR, a
inc DPTR
inc DPTR
djnz b, Macd1 ;Whole table processed?
dec SP
dec SP

Source: Maths Subroutines for the 8051 microcontroller, W.G.Marshall 2002

Related topics:
8051 Program - signed 16bit multiply divide   |   8051 Program - signed 16bit multiply Accumulate   |   8051 Program - unsigned 8bit multiplication   |   8051 Program - signed 32bit division   |   8051 Program - unsigned 32bit division   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment