Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Mult(input wire clock, input wire reset, input wire[31:0) InA, input wire[31:0) InB,
- input wire MultControl,
- output reg[31:0} Hi, output reg[31:0} Lo, output reg MultExit);
- --Baseado no algoritmo de booth https://en.wikipedia.org/wiki/Booth%27s_multiplication_algorithm#A_typical_implementation
- integer i = -1;
- reg [64:0] A; --Formato Geral [x + y + 1] -> 32 + 32 + 1 = 65
- reg [64:0] S;
- reg [64:0] P;
- reg [31:0] TwoComp;
- always @(posedge clk) begin
- if(reset) begin
- Hi = 32'b0; --ZERANDO $HI
- Lo = 32'b0; --ZERANDO $LO
- A = 65'b0; --Zerando A
- S = 65'b0; --Zerando S
- P = 65'b0; --Zerando P
- i = -1; --Zerando o iterador
- end
- if(MultControl == 1'b1) begin --Sinal de comeco
- i = 0; --for( -> int i = 0 <- ; i < 32; i++)
- A = {InA, 33'b0}; --Fill the most significant (leftmost) bits with the value of m.
- --Fill the remaining (y + 1) bits with zeros.
- TwoComp = (~a + 1'b1); --Notacao de Complemento a 2
- S = {TwoComp, 33'b0}; --Fill the most significant bits with the value of (−m) in
- --two's complement notation. Fill the remaining (y + 1) bits with zeros.
- P = {32'b0, b, 1'b0}; --Fill the most significant x bits with zeros. To the right of
- --this, append the value of r. Fill the least significant (rightmost) bit with a zero.
- MultExit = 1'b0; --Sinal de Saida = 0
- end
- case (P[1:0])
- --Determine the two least significant (rightmost) bits of P.
- -- If they are 01, find the value of P + A. Ignore any overflow.
- 2'b01: P = P + A;
- -- If they are 10, find the value of P + S. Ignore any overflow.
- 2'b10: P = P + S;
- -- If they are 00, do nothing. Use P directly in the next step.
- -- If they are 11, do nothing. Use P directly in the next step.
- endcase
- P = P >> 1; --Arithmetically shift the value obtained in
- --the last step by a single place to the right. Let P now equal this new value.
- if(P[63] == 1'b1) begin --Caso do Numero Negativo
- P[64] = 1'b1;
- end
- if(i < 32) begin --Iteracao do i for(int i = 0; i < 32; --> i++ <--)
- i = i + 1;
- end
- if(i == 32) begin --Algum momento i sera 32, ai os registradores serao setados e os valores resetados
- Hi = P[64:33]; --Assign do Hi
- Lo = P[32:1]; --Assign do Lo
- MultEnd = 1'b1; --sinal de saida = 1
- i = -1; --RESETING i
- A = 65'b0; --RESETING A
- S = 65'b0; --RESETING S
- P = 65'b0; --RESETING P
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement