다운/퍼 가실 때 댓글 부탁드려요. 그리고 받으신 자료 유료 레포트 사이트에 올리지 말아주세요.
1. 개 요
가. 산술 및 논리 연산 기능이 구현된 ALU를 구현해본다.
나. Subtractor를 구현을 새로운 모듈(감산기)로 구성하지 않고, 입력 b에 대한 보수의 형식을 취한 입력을 Adder에 넣어 Adder하나로 add, subtract, compare에 대한 연산을 수행할 수 있도록 한다.
다. func_sel과 result_sel에 의해서 어떠한 결과값이 나오는지 확인해본다.
2. 알고리즘
가. ALU 주요 기능
1) 산술연산 : 덧셈, 뺄셈, 비교 연산
‣ 반가산기, 전가산기를 사용하고, 음수는 2의 보수형태를 취해서 입력된다.
‣ 비교는 두 입력값에 대한 뺄셈의 결과로 확인한다.
2) 논리연산 : and, or 연산
‣ 두 입력에 대한 각 비트별 연산을 통해서 최종 결과를 확인한다.
나. ALU 회로도
|
|
1) ALU에서 구현하고자 하는 add, subtract, compare, and, or 연산은 Adder, AND Unit, OR Unit의 세가지 모듈로 구현이 가능하다.
2) and와 or 연산은 입력 A, B에 대해서 비트별 and, or 연산을 수행해준다.
3) add 연산은 입력 A, B가 Adder를 통해서 바로 결과가 나온다.
4) subtract와 compare는 B를 2의 보수를 취해서 add연산을 해야 하는데, Adder 모듈 전에 있는 MUX가 입력 B와 2의 보수를 취한 B'를 입력받아서 func_sel에 따라서 Adder에 B의 결과를 입력하게 된다.
5) subtract연산을 하고자 한다면 Adder는 2의 보수형태를 취한 B를 받아서 A와 add연산을 하고 그 결과는 A와 B를 subtract한 결과와 같아진다.
6) compare연산에 대한 결과는 subtract연산을 하고 뒤의 result_sel에 의해서 선택되며, A와 B의 차가 0보다 큰지 작은지에 따라서 대소비교가 가능해진다.
7) 이렇게 각각 모듈에 의해서 만들어진 결과들은 result_sel에 의해서 멀티플렉싱되어 하나가 선택되어 결과값으로 출력된다.
다. ALU select 신호에 따른 출력 결과표
|
menu |
func_sel |
Operation |
result_sel |
result(a, b) |
|
Adder |
0 |
Addition |
00 |
a + b |
|
Subtractor |
1 |
Subtraction |
00 |
a - b |
|
Comparator |
1 |
Subtraction |
01 |
if(a >= 0) 00000000 if(a < 0) 00000001 |
|
AND unit |
× |
AND |
10 |
a and b |
|
OR unit |
× |
OR |
11 |
a or b |
1) 위 표에서 func_sel은 adder와 subtractor를 구분해주며(comparator도 기본적으로는 subtract연산에 영향을 받는다), result_sel은 출력값에 대한 선택을 한다.
2) func_sel은 입력 B에 대한 2의 보수를 취하는 여부를 결정하며, 이는 AND unit과 OR unit 에 영향을 미치지 않는다.
3) compare연산으로 나온 결과 A와 B의 차이므로 0과의 대소비교를 통해서 최종 결과값을 결정한다.
3. 코 드
|
module alu(a, b, func_sel, result_sel, result); input [7:0] a, b; // 입력값 a, b input func_sel; // adder, subtractor, comparator 선택 input [1:0] result_sel; // adder(subtractor), comparator, and unit, or uint 선택 output [7:0] result; // 결과값 reg [7:0] result; reg [7:0] adder_result; // adder 결과 reg [7:0] and_result; // and 결과 reg [7:0] or_result; // or 결과 m_adder adder1(a, b, adder_result, func_sel); // adder 모듈 실행 m_and and1(a, b, and_result); // and 모듈 실행 m_or or1(a, b, or_result); // or 모듈 실행 always@(result, adder_result, and_result, or_result, result_sel) case(result_sel) // result_sel에 의해서 결과값 선택 2'b00 : result = adder_result; 2'b01 : begin if(adder_result >= 0) // a >= b 이면 result = 8'b00000000; else // a < b 이면 result = 8'b00000001; end 2'b10 : result = and_result; 2'b11 : result = or_result; endcase endmodule module m_adder(a, b, adder_result, func_sel); input [7:0] a, b; input func_sel; output [7:0] adder_result; // adder 결과값 wire [7:0] c; // 캐리를 위한 연결 변수 wire [7:0] b1; // 보수를 위한 연결 변수 m_complement com1(b, b1, func_sel); // b의 보수 모듈 실행 m_half_adder ha(a[0], b1[0], c[0], adder_result[0]); // 반가산기 모듈 실행 m_full_adder fa1(a[1], b1[1], c[0], c[1], adder_result[1]); // 반가산기 캐리를 받아 m_full_adder fa2(a[2], b1[2], c[1], c[2], adder_result[2]); // 7개 전가산기 모듈 실행 m_full_adder fa3(a[3], b1[3], c[2], c[3], adder_result[3]); m_full_adder fa4(a[4], b1[4], c[3], c[4], adder_result[4]); m_full_adder fa5(a[5], b1[5], c[4], c[5], adder_result[5]); m_full_adder fa6(a[6], b1[6], c[5], c[6], adder_result[6]); m_full_adder fa7(a[7], b1[7], c[6], c[7], adder_result[7]); endmodule |
|
module m_full_adder(a, b, cin, cout, adder_result); input a, b, cin; output cout, adder_result; wire c1, c2, s1; m_half_adder ha1(b, cin, c1, s1); // b와 캐리인을 반가산기로 계산 m_half_adder ha2(a, s1, c2, adder_result); // a와 계산된 s1 값을 반가산기로 계산 assign cout = c1 | c2; // 최종적으로 발생된 캐리를 cout에 저장 endmodule module m_half_adder(a, b, c, adder_result); input a, b; output c, adder_result; assign adder_result = a ^ b; // xor연산한 값을 결과비트에 저장 assign c = a & b; // and연산한 값을 캐리에 저장 endmodule module m_complement(b, b1, func_sel); input [7:0] b; input func_sel; output [7:0] b1; reg [7:0] tmp; // 보수 변환값을 저장하기 위한 임시 변수 always@(b, tmp, func_sel) case(func_sel) // func_sel에 따라서 보수를 취할지 결정함 1'b0 : tmp = b; 1'b1 : tmp = ~b + 1; endcase assign b1 = tmp; // 변환된 값을 b1에 저장 endmodule module m_and(a, b, and_result); input [7:0] a, b; output [7:0] and_result; assign and_result = a & b; // a와 b를 and연산함 endmodule module m_or(a, b, or_result); input [7:0] a, b; output [7:0] or_result; assign or_result = a | b; // a와 b를 or연산함 endmodule |
4. 파형 및 분석
|
|
|
|
|
|
가. 위 파형은 입력값 a, b에 대한 add, subtract, compare, and, or 연산 결과를 보여준다.
나. add와 subtract연산은 결과를 확인하기 쉽게 하기 위해서 signed value로 표현하였다.
다. 각 모듈에 대한 딜레이 시간이 있으므로 파형출력 시간을 짧게 잡으면 제대로 된 연산 결과가 출력되지 않음으로 grid를 500ns로 줘서 딜레이에 따른 잘못된 출력이 발생하는 것을 방지하였다.
라. (1)에서 func_sel이 0, result_sel이 00이므로 add연산을 수행하는데 a는 7, b가 2이므로 그 합인 9가 result로 출력되었다.
마. (2)에서 func_sel이 1, result_sel이 00이므로 subtract연산을 수행하는데, a는 10, b가 3이므로 그 차인 7이 result로 출력되었다.
바. compare 연산은 func_sel이 1이고, result_sel이 01일 때만 수행되므로, (3)에서 func_sel이 0일 때는 결과값이 00000000으로 아무런 값이 들어가지 않으며, (4)에서 result_sel이 01일 때는 a와 b를 비교하여, a >= b이므로 결과값에 00000000이 출력된다.
사. and와 or연산은 func_sel에 상관없이 result_sel에 의해서만 결정되는데, (5)에서 result_sel은 10이므로 and 연산을 수행하여, a는 00110100, b가 00010001이므로 결과는 00010000이고, (6)에서는 result_sel이 11이므로 or 연산을 수행하여, a는 00110111, b가 00010010이므로 결과는 00110111이 출력된다.
아. 구현된 ALU는 입력값에 대한 정상적인 결과가 출력되었다.
※ 참고 문헌
가. 디지털 시스템 2nd Edition(인터비전 / 송상훈 외 7인 공역)
나. http://www.terms.co.kr/ALU.htm
다. http://mpu.yonsei.ac.kr/Lecture/nrl/ALURegisterFile.htm
라. http://vision.kongju.ac.kr/lecture/digital/chap06/digital06.htm
마. http://sam.snut.ac.kr/~haklyun/digital/homepage.htm
'레포트 자료' 카테고리의 다른 글
| 컴퓨터구조 설계 및 실험 - 16bit CPU (Instruction Fetch & Decode) (1) | 2009/02/02 |
|---|---|
| 컴퓨터구조 설계 및 실험 - register (0) | 2009/02/02 |
| 컴퓨터구조 설계 및 실험 - ALU (1) | 2009/02/02 |
| 컴퓨터구조 설계 및 실험 - 유한상태기계(FSM - Finite State Machine) (2) | 2009/01/30 |
| 컴퓨터구조 설계 및 실험 - ripple carry adder(가산기) 및 감산기 (4) | 2009/01/29 |
| 컴퓨터구조 설계 및 실험 - D Flip-Flop & Decoder (1) | 2009/01/29 |


alu.zip



