PRA2
PRA2
iTIC http://itic.cat
April 2016
VHDL Implementation of the Status Register
type status_reg is
record
Z : std_logic ;
C : std_logic ;
end record ;
signal pr_SR ,
nx_SR : status_reg ;
Control Unit
I Input: Present opcode
I Decode the instruction
I Generate signals:
I Register write enable reg_we
I Output multiplexer selection: decide if data written to register
comes from:
I The present opcode (such as LDI)
I The ALU (such as ADC)
I Generate d and r register addresses d_reg, s_reg
I Indicate the desired operation to the ALU alu_op
Control: reg_we
out_mux
16
8 k
pr_op 4 d_reg
4 r_reg
3 alu_op
VHDL Implementation of the Control Unit (1/2)
alu_op ALU:
pr_SR
(Z,C) 8 2
alu_out nx_SR
(Z,C)
VHDL implementation of the ALU
ALU : process ( alu_op , alu_in_a , alu_in_b , pr_SR , add_temp )
begin
nx_SR <= pr_SR ; -- by default , p r e s e r v e status r e g i s t e r
add_temp <= ( others = > ’ - ’);
case alu_op is
when ALU_MOV = > -- - - - - - - - - - - - - - - - - - - - MOV : in_b --> out
alu_out <= alu_in_b ;
when ALU_ADC = > -- - - - - - - - - - - - - - - - - - - - ADC : Carry in / out
add_temp <= s t d _ l o g i c_ v e c t o r ( -- a u x i l i a r SLV (9..0)
unsigned ( ’0 ’ & alu_in_a & ’1 ’) +
unsigned ( ’0 ’ & alu_in_b & pr_SR . C )); -- Carry In
alu_out <= add_temp (8 downto 1);
nx_SR . C <= add_temp (9); -- Update Carry Flag
if add_temp (8 downto 1) = x " 00 " then -- Update Zero Flag
nx_SR . Z <= ’1 ’;
else
nx_SR . Z <= ’0 ’;
end if ;
when others = > -- - - - - - - - - - - - - - - - - - - - - - - - - Should not happen
alu_out <= ( others = > ’ - ’); -- Don ’ t care
end case ;
end process ;
Register Data-In Multiplexer
nx_reg
8
out_mux
8 8
k alu_out
VHDL implementation of the Register Multiplexer
I Registered signals
I Program counter pr_pc
I Stauts register pr_SR
pr_pc pr_SR
(Z,C)
2
+1
8 2
nx_pc clk
clk nx_SR
(Z,C)
VHDL implementation of the Synchronous Elements
I Entity
entity mini_avr_01 is
port (
clk : in std_logic ;
reset : in std_logic ;
-- Let ’ s have some r e g i s t e r s as outputs :
r16 : out s t d _ l o g i c _ v e c t o r ( 7 downto 0);
r17 : out s t d _ l o g i c _ v e c t o r ( 7 downto 0)
);
end entity ;
NOP
LDI r16,x83
x83+x83=x106 ADC r16,r16
ADC r16,r16
MOV r17,r16
NOP