70 likes | 88 Views
Integer Square Root. Lecture L8.0. Integer Square Root. unsigned long sqrt(unsigned long a){ unsigned long square = 1; unsigned long delta = 3; while(square <= a){ square += delta; delta += 2; } return (delta/2 - 1); }. Integer Square Root.
E N D
Integer Square Root Lecture L8.0
Integer Square Root unsigned long sqrt(unsigned long a){ unsigned long square = 1; unsigned long delta = 3; while(square <= a){ square += delta; delta += 2; } return (delta/2 - 1); }
Integer Square Root unsigned long sqrt(unsigned long a){ unsigned long square = 1; unsigned long delta = 3; while(square <= a){ square += delta; delta += 2; } return (delta/2 - 1); }
Datapath unsigned long sqrt(unsigned long a){ unsigned long square = 1; unsigned long delta = 3; while(square <= a){ square += delta; delta += 2; } return (delta/2 - 1); } • The following steps can be used to create a datapath for implementing an algorithm. • Draw a register (rectangular box with input at the top and output at the bottom) for each variable in the algorithm. For the algorithm in Listing 1 these would include a, square, delta, and outreg (for the return value). Each register will also have a reset, clock, and load inputs. When the reset signal is high, the output of the register will be a predetermined initial value. If the load signal is high, then on the next rising edge of the clock signal the input value will be loaded into the register and appear on the output. • Define combinational blocks to implement any necessary arithmetic or logical operation. • Connect the outputs of the registers to the inputs of the appropriate arithmetic and logical operations, and connect the outputs of the arithmetic and logical operations to the appropriate registers. Multiplexers can be used if the input to a register can come from more than one source.
State Diagrams unsigned long sqrt(unsigned long a){ unsigned long square = 1; unsigned long delta = 3; while(square <= a){ square += delta; delta += 2; } return (delta/2 - 1); }