Download presentation
Presentation is loading. Please wait.
Published byΒαραββᾶς Αποστόλου Modified over 5 years ago
1
Step 2 in behavioral modeling. Use of procedures.
Project Step 5 Step 2 in behavioral modeling. Use of procedures. 1/8/ L11 Project Step 5 Copyright Joanne DeGroat, ECE, OSU
2
The nature of the process
Will still use P, K, and R to control the operation. Previously have use Pctl to compute Pint, Kctl to compute Ki, and then Rctl to generate the final result. Now will use a combined P&K&R to choose the operation being performed For op A have P,K,R of 1100,1111,1100 For op A AND B have 1000,1111,1100 For op A + B have 0110,0001,0110 1/8/ L11 Project Step 5 Copyright Joanne DeGroat, ECE, OSU
3
Copyright 2006 - Joanne DeGroat, ECE, OSU
continued Then we can use a case statement on a variable that concatenates P&K&R to choose which operation to perform. opersw := P & K & R; --Note use of variable CASE opersw IS WHEN “ ” => Zout <= A; Cout <= ‘0’; --op A WHEN “ ” => neg(A,Ztemp,CoutTemp); Zout <= Ztemp; Cout<= CoutTemp; -- Ztemp and CoutTemp are variables WHEN … 1/8/ L11 Project Step 5 Copyright Joanne DeGroat, ECE, OSU
4
Copyright 2006 - Joanne DeGroat, ECE, OSU
Note on operations For logical operation can do vector operations Zout <= A AND B; Where A and B are the input bit vectors And the vectors must be of the same size for a bit-wise vector operation Arithmetic operations will need procedures One for Add One for 2’s complement One for Subtract that can be an implementation of binary subtraction, or subtraction using 2’s complement addition 1/8/ L11 Project Step 5 Copyright Joanne DeGroat, ECE, OSU
5
Copyright 2006 - Joanne DeGroat, ECE, OSU
The procedures The procedures are to be declared in the declarative region of the process In the declarative region of the process can only declare a procedure body. And thus no procedure declaration part is done. Scope of procedure is limited to just this process. (We will later move these to a package and write the procedure declaration.) 1/8/ L11 Project Step 5 Copyright Joanne DeGroat, ECE, OSU
6
Copyright 2006 - Joanne DeGroat, ECE, OSU
Addition Procedure BINADD A procedure for binary addition using sequential statements. Will make the arguments to the procedure unconstrained so that it will be capable of adding words of any length (constraint that both inputs are the same index range). (right now size is 8 bits, later will use the procedure for 16 bit arguments). 1/8/ L11 Project Step 5 Copyright Joanne DeGroat, ECE, OSU
7
Unconstrained declaration
PROCEDURE binadd (l,r : IN BIT_VECTOR; cin : IN BIT; sum : OUT BIT_VECTOR; cout : OUT BIT) IS VARIABLE carry : BIT: --internal variable carry BEGIN carry := cin; FOR i IN l’reverse_range LOOP -- compute sum for position I, sum := … -- compute carry out for position I into carry variable, carry := … END LOOP; -- assign cout from final value of carry - - I provide a lot but you must finish this 1/8/ L11 Project Step 5 Copyright Joanne DeGroat, ECE, OSU
8
Copyright 2006 - Joanne DeGroat, ECE, OSU
Highlights on the code Inputs are “unconstrained” – they can be any size We will later use these same procedures in a package and the data size will be 16 bits. Outputs of the procedure are variables. These need to be assigned to the appropriate signal. Need to use attribute for loop parameter as shown If L declared (x downto 0) such that leftmost bit is the msb and highest index THEN L’REVERSE_RANGE has the designation 0 to x 1/8/ L11 Project Step 5 Copyright Joanne DeGroat, ECE, OSU
9
Now use the procedure in the case
Within the main process BEGIN … CASE opersw IS WHEN “ ” => Zout <= A; Cout <= ‘0’; --op A WHEN “0110xxxxxxxx” => --and add binaddd(a,b,cin,sum,vcout); zout <= sum; cout<= vcout; WHEN “xxxxxxxxxxxx” => … 1/8/ L11 Project Step 5 Copyright Joanne DeGroat, ECE, OSU
10
Overall look of code – where things go
Same ENTITY as before ARCHITECTURE v_3 OF adder_8 IS BEGIN --A single process as just described PROCESS (sensitivity list) **** PROCEDURES are declared here **** Local Variables opersw:= CASE opersw……. END PROCESS; END v_3; 1/8/ L11 Project Step 5 Copyright Joanne DeGroat, ECE, OSU
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.