Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.81 KB | None | 0 0
  1. module Mult(input wire clock, input wire reset, input wire[31:0) InA, input wire[31:0) InB,
  2.             input wire MultControl,
  3.             output reg[31:0} Hi, output reg[31:0} Lo, output reg MultExit);
  4.             --Baseado no algoritmo de booth https://en.wikipedia.org/wiki/Booth%27s_multiplication_algorithm#A_typical_implementation
  5.  
  6.     integer i = -1;
  7.     reg [64:0] A;  --Formato Geral [x + y + 1] -> 32 + 32 + 1 = 65
  8.     reg [64:0] S;
  9.     reg [64:0] P;
  10.     reg [31:0] TwoComp;
  11.  
  12.     always @(posedge clk) begin
  13.         if(reset) begin
  14.             Hi = 32'b0; --ZERANDO $HI
  15.             Lo = 32'b0; --ZERANDO $LO
  16.             A = 65'b0; --Zerando A
  17.             S = 65'b0; --Zerando S
  18.             P = 65'b0; --Zerando P
  19.             i = -1; --Zerando o iterador
  20.         end
  21.  
  22.         if(MultControl == 1'b1) begin  --Sinal de comeco
  23.             i = 0;   --for( -> int i = 0 <- ; i < 32; i++)
  24.             A = {InA, 33'b0}; --Fill the most significant (leftmost) bits with the value of m.
  25.             --Fill the remaining (y + 1) bits with zeros.
  26.             TwoComp = (~a + 1'b1); --Notacao de Complemento a 2
  27.             S = {TwoComp, 33'b0}; --Fill the most significant bits with the value of (−m) in
  28.             --two's complement notation. Fill the remaining (y + 1) bits with zeros.
  29.             P = {32'b0, b, 1'b0}; --Fill the most significant x bits with zeros. To the right of
  30.             --this, append the value of r. Fill the least significant (rightmost) bit with a zero.
  31.             MultExit = 1'b0; --Sinal de Saida = 0
  32.         end
  33.  
  34.         case (P[1:0])
  35.         --Determine the two least significant (rightmost) bits of P.
  36.         --  If they are 01, find the value of P + A. Ignore any overflow.
  37.         2'b01: P = P + A;
  38.         --  If they are 10, find the value of P + S. Ignore any overflow.
  39.         2'b10: P = P + S;
  40.         --  If they are 00, do nothing. Use P directly in the next step.
  41.         --  If they are 11, do nothing. Use P directly in the next step.
  42.         endcase
  43.         P = P >> 1; --Arithmetically shift the value obtained in
  44.         --the last step by a single place to the right. Let P now equal this new value.
  45.        
  46.         if(P[63] == 1'b1) begin --Caso do Numero Negativo
  47.             P[64] = 1'b1;
  48.         end
  49.        
  50.         if(i < 32) begin --Iteracao do i  for(int i = 0; i < 32; --> i++ <--)
  51.             i = i + 1;
  52.         end
  53.  
  54.         if(i == 32) begin --Algum momento i sera 32, ai os registradores serao setados e os valores resetados
  55.             Hi = P[64:33]; --Assign do Hi
  56.             Lo = P[32:1]; --Assign do Lo
  57.             MultEnd = 1'b1; --sinal de saida = 1
  58.  
  59.             i = -1; --RESETING i
  60.             A = 65'b0; --RESETING A
  61.             S = 65'b0; --RESETING S
  62.             P = 65'b0;  --RESETING P
  63.         end
  64.     end
  65.  
  66. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement