태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

티스토리 툴바

달력

052012  이전 다음

  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  •  
  •  

module FA( InA, InB, CarryIn, Sum, CarryOut );

input InA, InB, CarryIn;
output Sum, CarryOut;

reg Sum, CarryOut;

always @ (*)
begin
 {CarryOut,Sum} = InA+ InB+CarryIn;
end

endmodule


module alu0( A, B, Binvert, CarryIn, Operation, CarryOut, Result, less );

input A, B, Binvert, CarryIn, Operation, less;

output CarryOut, Result;

reg Result;
wire CarryOut, B_Sel;

FA FA_0( .Sum(FA_Sum), .CarryIn(CarryIn), .InA(A), .InB(B), .CarryOut(CarryOut) );
assign B_Sel = (Binvert==0) ? B : ~B;

always @(*)
begin
 case(Operation)
 0:
  Result <= A & B_Sel;
 1:
  Result <= A | B_Sel;
 2:
  Result <= FA_Sum;
 3:
  Result <= less;
 default:
  Result <= 0;
 endcase
end

endmodule


module alu1( A, B, Binvert, CarryIn, Operation, Result, less, Set, Overflow );

input A, B, Binvert, CarryIn, Operation, less;

output Result, Set, Overflow;

reg Result, Set, Overflow;
wire CarryOut, B_Sel;

FA FA_0( .Sum(FA_Sum), .CarryIn(CarryIn), .InA(A), .InB(B), .CarryOut(CarryOut) );
assign B_Sel = (Binvert==0) ? B : ~B;

always @(*)
begin
 case(Operation)
 0:
  Result <= A & B_Sel;
 1:
  Result <= A | B_Sel;
 2:
  Result <= FA_Sum;
 3:
  Result <= less;
 default:
  Result <= 0;
 endcase
end

always@(*)
begin
 Set <= FA_Sum;
 Overflow <= CarryIn ^ CarryOut;
end

endmodule


module ALU_top( InA, InB, Binvert, Operation, Result, Zero, Overflow );

parameter width = 32;

input [width-1:0] InA, InB;
input Binvert;
input [1:0] Operation;

output [width-1:0] Result;
output Zero, Overflow;

wire Set, ov;
wire [width-1:0] CarryOut;


alu0 alu_fs(  .A(InA[0]), .B(InB[0]),
      .Binvert(Binvert), .CarryIn(Binvert),
      .Operation(Operation), .CarryOut(CarryOut[0]),
      .Result(Result[0]), .less(Set) );
      
genvar i;
generate for ( i = 1; i < 31; i=i+1 )
begin:gs1
 alu0 alu_gs1( .A(InA[i]), .B(InB[i]),
      .Binvert(Binvert), .CarryIn(CarryOut[i-1]),
      .Operation(Operation), .CarryOut(CarryOut[i]),
      .Result(Result[i]), .less(1'b0) );
end
endgenerate

alu1 alu_fi(  .A(InA[31]), .B(InB[31]),
      .Binvert(Binvert), .CarryIn(CarryOut[30]),
      .Operation(Operation),
      .Result(Result[31]), .less(1'b0),
      .Set(Set), .Overflow(Overflow) );

assign ov = |Result;
assign Zero = ~ov;

endmodule

 

 

 

 

//  하면서 고민했던거 고찰에 적어넣으면 됨.

저작자 표시
Posted by hk4u

컴퓨터 구조 수업을 듣다가 ALU 부분에서 곱셈에 대해 배울때 조사했던 Booth's algorithm에 대한 정리입니다.

기본적인 곱셈의 경우 multiflier의 해당 자리수가 multiflicant를 product에 더해주고 0일 경우 0을 더해준뒤 1bit left shift를 해주고 난뒤 multiflier의 다음 자리수를 0,1인지 비교하여 product에 더해주게 된다
1010 * 1001 일 경우(부호비트 생략)

     0110  (6)
  * 1001  (9)
     0110
    0000
   0000
  0110
  0110110
이런식으로 구하게 되며 자리수 만큼의 반복을 거쳐야 계산이 완료하게 된다 지금의 경우는 양의 정수끼리의 곱셈이며 음의 정수일 경우 부호비트에 대한 처리를 따로 해줘야한다.

이것을 좀더 빠르게 하기위해 나온 것이 Booth's algorithm이다. Booth's algorithm은 음수와의 곱셈을 지원하며 한번에 2bit씩 left shift를 하며 반복 횟수를 줄여주게 된다. Booth's algorithm은 multiflier의 맨오른쪽 bit 오른쪽에 0이 하나 더 붙이고 1자리씩 겹치게 3자리로 끈어서 Booth's Table에 대입한다

Booth's Table
011      2     multiflicant를 1bit left shift 시킨다음 product에 더해준다
010      1     multiflicant를 product에 더해준다
001      1     multiflicant를 product에 더해준다
000      0     0을 product에 더해준다
111      0     0을 product에 더해준다
110     -1    multiflicant를 2의보수로 변경한 다음 product에 더해준다
101     -1    multiflicant를 2의보수로 변경한 다음 product에 더해준다
100     -2    multiflicant를 2의보수로 변경한 다음1bit left shift 시킨다음 product에 더해준다

위의 문제를 여기에 맞춰서 풀어준다면
0110*1001(첫자리를 부호비트로 생각)      (6)*(-7)

multiflier를 끈어주어야한다
1001에 0을 하나더 붙여서 10010으로 만들고 1자리씩 겹치게 3자리로 끈는다.
1 0|0|1 0
100 010 2개가 나오게 된다

이것을 booth's table에 대입하게 되면
100 010
-2   1
이며 연산은 오른쪽에서 왼쪽으로 간다

처음은 1이므로 multiflicant를 product에 더해주면 된다
0000+0110
product:0110

2bit left shift를 한다.

다음은 -2이므로 multiflicant를 2의보수로 변경한 다음1bit left shift 시킨다음 product에 더해준다
0000110+1010000
product:1010110 (-42)
6*(-7)=-42
위와 같은 결과가 나오게 된다
위쪽에선 4번의 반복으로 나왔던 결과가  2번의 반복으로 가능하며, 부호비트가 있는 데이터의 연산이 가능하게 됩니다

 

 

[펌] http://baical.egloos.com/1104025

 

내가 다시 쓰긴 귀찮...으니까.. 잘 써진걸 퍼오는거죠 ㅜㅜㅋ

저작자 표시

'From University' 카테고리의 다른 글

Booth's algorithm  (0) 2012/04/27
디시설 - 5주차  (0) 2012/03/30
통신 과제 ( ~12/16일 )  (0) 2011/12/01
-  (0) 2011/11/10
언제나 처럼 통신이론  (0) 2011/11/03
통신이론 과제  (0) 2011/10/27
Posted by hk4u

http://recruit.hyundai.com/index.jsp

 

 

현대자동차에서 4월 9일부터 인턴 모집을 시작하네요.

관심있는 분들은 지원 ㄱㄱ

저작자 표시

'About Me > Essey - In My Life' 카테고리의 다른 글

현대자동차 인턴 모집 공고  (0) 2012/04/06
요즘 사는게  (0) 2011/05/20
동인천 닭강정.  (0) 2011/04/29
사랑 그건 무슨 감정일까요 ?  (0) 2011/04/25
결국  (0) 2011/02/18
드디어!!  (1) 2011/02/01
Posted by hk4u