Project Step 5 Step 2 in behavioral modeling
Project Step 5 Step 2 in behavioral modeling. Use of procedures. 1/8/2007 - L 11 Project Step 5 Copyright 2006 - Joanne De. Groat, ECE, OSU 1
The nature of the process o o o 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 n n n 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/2007 - L 11 Project Step 5 Copyright 2006 - Joanne De. Groat, ECE, OSU 2
continued o Then we can use a case statement on a variable that concatenates P&K&R to choose which operation to perform. n n n n n opersw : = P & K & R; --Note use of variable CASE opersw IS WHEN “ 110011111100” => Zout <= A; Cout <= ‘ 0’; --op A WHEN “ 001111000110” => neg(A, Ztemp, Cout. Temp); Zout <= Ztemp; Cout<= Cout. Temp; -- Ztemp and Cout. Temp are variables WHEN … 1/8/2007 - L 11 Project Step 5 Copyright 2006 - Joanne De. Groat, ECE, OSU 3
Note on operations o For logical operation can do vector operations n n n o 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 n n n 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/2007 - L 11 Project Step 5 Copyright 2006 - Joanne De. Groat, ECE, OSU 4
The procedures o o o 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/2007 - L 11 Project Step 5 Copyright 2006 - Joanne De. Groat, ECE, OSU 5
Addition o Procedure n n 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/2007 - L 11 Project Step 5 Copyright 2006 - Joanne De. Groat, ECE, OSU 6
Unconstrained declaration n n n 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/2007 - L 11 Project Step 5 Copyright 2006 - Joanne De. Groat, ECE, OSU 7
Highlights on the code o o 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 n n 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/2007 - L 11 Project Step 5 Copyright 2006 - Joanne De. Groat, ECE, OSU 8
Now use the procedure in the case o Within the main process n n n n n BEGIN … CASE opersw IS WHEN “ 110011111100” => Zout <= A; Cout <= ‘ 0’; --op A WHEN “ 0110 xxxx” => --and add binaddd(a, b, cin, sum, vcout); zout <= sum; cout<= vcout; WHEN “xxxxxx” => … 1/8/2007 - L 11 Project Step 5 Copyright 2006 - Joanne De. Groat, ECE, OSU 9
Overall look of code – where things go o Same ENTITY as before n n ARCHITECTURE v_3 OF adder_8 IS BEGIN o o --A single process as just described PROCESS (sensitivity list) n n o BEGIN n n o n **** PROCEDURES are declared here **** Local Variables opersw: = CASE opersw……. END PROCESS; END v_3; 1/8/2007 - L 11 Project Step 5 Copyright 2006 - Joanne De. Groat, ECE, OSU 10
- Slides: 10