Xilinx UG129 Answering Machine User Manual


 
PicoBlaze 8-bit Embedded Microcontroller www.xilinx.com 29
UG129 (v1.1.2) June 24, 2008
Processing Data
R
If multiplication performance is important to the application, connect one of the FPGA’s
18x18 hardware multipliers the PicoBlaze I/O ports, as shown in Figure 3-15. The
hardware multiplier computes the 16-bit result in less than one instruction cycle.
Figure 3-16 shows the routine required to multiply two 8-bit values using the hardware
multiplier. This same technique can be expanded to multiply two 16-bit values to produce
a 32-bit result. This example also illustrates how to use FPGA logic attached to the
PicoBlaze microcontroller to accelerate algorithms.
Figure 3-14: 8-bit by 8-bit Multiply Routine Produces a 16-bit Product
; Multiplier Routine (8-bit x 8-bit = 16-bit product)
; ==================================================
; Shift and add algorithm
;
mult_8x8:
NAMEREG s0, multiplicand
; preserved
NAMEREG s1, multiplier ; preserved
NAMEREG s2, bit_mask ; modified
NAMEREG s3, result_msb ;
most-significant byte (MSB) of result,
; modified
NAMEREG s4, result_lsb ; least-significant byte (LSB) of result,
; modified
;
LOAD bit_mask, 01 ; start with least-significant bit (lsb)
LOAD result_msb, 00 ; clear product MSB
LOAD result_lsb, 00 ; clear product LSB (not required)
;
; loop through all bits in multiplier
mult_loop: TEST multiplier, bit_mask ; check if bit is set
JUMP Z, no_add ; if bit is not set, skip addition
;
ADD result_msb, multiplicand ; addition only occurs in MSB
;
no_add: SRA result_msb ; shift MSB right, CARRY into bit 7,
; lsb into CARRY
SRA result_lsb ; shift LSB right,
; lsb from result_msb into bit 7
;
SL0 bit_mask ; shift bit_mask left to examine
; next bit in multiplier
;
JUMP NZ, mult_loop ; if all bit examined, then bit_mask = 0,
; loop if not 0
RETURN ; multiplier result now available in
; result_msb and result_lsb
T
If reading this document in Adobe Acrobat,
use the Select Text tool to select code snippets,
then copy and paste the text into your text editor.